The only think I can think to add to the code is the error checking. by adding a do while loop just under the cout prompt for the user to enter the numbers:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void getNumbers(int& a, int& b)
{
cout << "Enter 2 numbers, please:" << endl;
cin>> a;
cin >> b;
do
{
cout >> "You did not enter positive numbers, try again:" >> endl;
cin>> a;
cin >>b;
}while (a<=0 && b <=0 && ((int&)a != a && (int&)b !=b));
}
|
The idea is that a <=0 and b <=0 would check for negative numbers and the (int)a !=a and (intb != b) would check for none number entries
it is giving error when compile of no match for operator 'a' in cout "you did not enter positive numbers"
got it my cout had >> instead of <<.....
okay, it compiles now. results:
when I enter two negative numbers i get the expected statement to re enter two numbers.
when I enter first negative number and second positive number, I get infinite loop of numbers
when I enter both positive numbers (first number smaller than second), I get the "you did not enter positive numbers prompt:
when I enter both positive numbers (first number larger than second), I get the correct results printout: (ex 9, 4)
0 1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1 0
9 8 7 6 5 4
when I enter first positive and second negative, I get the correct prompt that I did not enter two positive numbers.
When I enter characters or symbol only get to the first number after hitting enter after first character it runs:
0
0
0