Hello I have an assignment from class that I desperately need help with
So I am to make a program that asks user to input a positive integer
e.g 1234, 234, 123456
However if the user inputs any 1 or 0 in the integer e.g 0234, 2314
the program will validate the number and
it will reject that integer every time
and ask the user to input a integer again.
I was taught in class that I would need to use to do while loop
however I now face 2 problems.
1.the while condition is too long and I can only account up to 5 digit long input,
I need another way to set the condition while account for any digit long integer.
2.integer/10%10 == 0 this particular line will reject everything even if i put in a 2,3,4 or 23456. Hence I did not bother to add in the next
integer/100%10 == 0
I cannot think of another way to reject a 0 not using this condition.
I hope someone could help me out here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
using namespace std;
int main()
{
int integer,temp;
do
{
cout << "Please enter a positive integer: ";
cin >> integer;
}
while( integer%10 ==1 || integer/10%10 ==1 ||
integer/100%10== 1 || integer/1000%10==1 ||
integer/10000%10==1|| integer/100000%10==1||
integer%10 == 0 || integer/10%10 == 0 );
return 0;
}
|