Commit 55df72a4 authored by Michael's avatar Michael

michael.davityan:exercise_07_15v2

parent 55613137
Error 1: Input number is wrong. It must be in range [10, 100].
Error 1: Input number is wrong. It must be in range [10, 100].
......@@ -4,29 +4,28 @@
int
main()
{
const int ARRAY_SIZE = 20;
const int ARRAY_SIZE = 19;
int numbersHoldingArray[ARRAY_SIZE] = {0};
for (int count = 1; count <= ARRAY_SIZE; ++count) {
int duplicateDetectVariable = 0;
for (int count = 0; count <= ARRAY_SIZE; ++count) {
bool duplicateDetectVariable = true;
int number;
if (::isatty(STDIN_FILENO)) {
std::cout << "insert number" << count << ": ";
std::cout << "Input number" << count + 1 << ": ";
}
std::cin >> number;
if (number < 10 || number > 100) {
std::cerr << "Error 1: wrong number(must be from 10 to 100).\n";
std::cerr << "Error 1: Input number is wrong. It must be in range [10, 100].\n";
return 1;
}
for (int arrayIndex = 0; arrayIndex < count; ++arrayIndex) {
for (int arrayIndex = 0; arrayIndex <= count && arrayIndex < ARRAY_SIZE; ++arrayIndex) {
if (numbersHoldingArray[arrayIndex] == number) {
++duplicateDetectVariable;
duplicateDetectVariable = false;
break;
}
}
if (0 == duplicateDetectVariable) {
numbersHoldingArray[count - 1] = number;
if (duplicateDetectVariable) {
numbersHoldingArray[count] = number;
std::cout << number << std::endl;
} else {
std::cout << "duplicate" << 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