Commit cf7954c1 authored by Believer Programmers' Club's avatar Believer Programmers' Club

Merge branch 'Bbranch7.15' into 'master'

michael.davityan:exercise_07_15

See merge request bpcarm/trainings2017!1432
parents d0b5b081 000fa79e
progname=exercise_07_15
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
all: test1 test2 test3
debug/$(progname): debug/$(progname).o
$(CC) $(CFLAGS) $< -o $@
debug/%.o: debug/%.s
$(CC) -c $(CFLAGS) $< -o $@
debug/%.s: debug/%.ii
$(CC) -S $(CFLAGS) $< -o $@
debug/%.ii: %.cpp | debug
$(CC) -E $(CFLAGS) $< -o $@
debug:
mkdir -p debug
clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
.SECONDARY: debug/%.ii debug/%.s
12
32
45
67
12
45
32
78
90
100
36
57
68
57
36
100
63
22
33
77
11
12
13
34
35
36
75
74
87
65
23
33
99
96
77
78
56
54
43
47
11
12
13
34
35
36
75
74
87
65
23
33
99
96
77
78
56
54
43
47
Error 1: Input number is wrong. It must be in range [10, 100].
#include <iostream>
#include <unistd.h>
int
main()
{
const int ARRAY_SIZE = 19;
int numbersHoldingArray[ARRAY_SIZE] = {0};
for (int count = 0; count <= ARRAY_SIZE; ++count) {
int number;
if (::isatty(STDIN_FILENO)) {
std::cout << "Input number" << count + 1 << ": ";
}
std::cin >> number;
if (number < 10 || number > 100) {
std::cerr << "Error 1: Input number is wrong. It must be in range [10, 100].\n";
return 1;
}
bool duplicateDetectVariable = true;
for (int arrayIndex = 0; arrayIndex < count; ++arrayIndex) {
if (numbersHoldingArray[arrayIndex] == number) {
duplicateDetectVariable = false;
break;
}
}
if (duplicateDetectVariable) {
numbersHoldingArray[count] = number;
std::cout << number << std::endl;
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment