Array Function

I am confused about writing the two error conditions.

Your function needs to ask the user the number of digits in the number, and then inputs the actual digits in reverse. We are reversing the digits so that the 0th element of the array lines up with the ones digit, the 1st element of the array lines up with the tens digits, and so forth.

Error Condition 1: If the user types a number of digits less than or equal to 0 or a size that would exceed the size of your array, prompt the user again.

Error Condition 2: If the user types a character that is not a digit while typing the number, input the rest of the digits, and then prompt the user to enter the number again.

Here is my code thus far:(does the error condition go inside the do while loop, or in a different function, or in the int main.

#include <iostream>
using namespace std;


int const ARRAY_SIZE = 20;
void print_array (char (&array)[ARRAY_SIZE]);
void storing_array (char (&array)[ARRAY_SIZE]);
int main()
{
int i;
char array [ARRAY_SIZE];
cout << "Enter the number of digits: ";



return 0;
}

//--------------------------end of main//

void print_array(char (&array)[ARRAY_SIZE])
{

int i; //initializing i to be the first index without the character 0
for (i=ARRAY_SIZE -1; i >=0; i--) {

if (array[i] != '0') break;
}

for (; i >0; i--) { //printing the array in reverse
cout << array[i];
}

}
void storing_array(char (&array)[ARRAY_SIZE])
{
int i;
//promting the user to imput

do {
cout << "Enter the number of digits: ";
for (i= ARRAY_SIZE-1; i >=0; i --) {
cin >> array[i];
}

} while( );

}
An easy way to validate input is to follow this pattern:
1
2
3
4
5
6
while (true) {
   // prompt for input
   // read input
   if (input is valid) break;
   // print error message
}
Topic archived. No new replies allowed.