I have recently started to learn about C++ and so far I started on data validation anyways I want this program to reject the integer should the user enter said integer containing a 1 or a 0 e.g 1234, 0222 so I thought about it and came up with the code below. However I now face a problem in this particular line
while (temp > 0 )
It would work if i was rejecting any other number say 2,3,4 but since I want to reject 0 this becomes illogical. How should i change the condition so that 0 will reject and ask the user to input again?
Edit: I managed to reject 0 or 1 in the middle of the integer e.g 234152, 234013
However I have no way to reject if the user enters 0234
#include <iostream>
using namespace std;
int main ()
{
int n, temp, temp2 ,counter;
bool check = false;
counter = 0;
do
{
check = false;
cout << "Enter a positive integer: ";
cin >> n;
temp = n;
temp2= n;
while (!check && n > 0 )
{
if( n % 10 ==1 || n % 10 == 0)
{
check = true;
}
else
n = n/ 10;
}
}
while(check == true || n < 0);
while(n == 0 || check == 1);