I am having an issue. I need to check whether the user enters a digit greater than 0. If so the user needs to be reprompted. If 23409932 is entered then the 0 entered should be caught and the proper messaage displayed. Here is my code and please somebody help.

int userInput (int numberInput)

{   
    int index;
    int remains;

    cout << endl;
    cout << " Enter a positive number count: ";
    cin  >> numberInput;

    while (numberInput > 0) {
       index = numberInput % 10;

       if (index == 0) {
          cout << " Error! Enter a positive number count: ";
          cin  >> numberInput;
          numberInput = numberInput / 10;
       }
       else {
          return numberInput;
       }
    }
cout << " Enter a positive number count: ";
cin >> numberInput;

    if(numberInput > 0) 
    {
    index = numberInput % 10;
    cout<<"index is :"<<index;
    }
    else if
     {
     cout << " Error! Enter a positive number count: ";
    cin >> numberInput
    }

The OP wants to check the existence of 0 in the number only if loop wont suffice , u will have to iterate within a while loop and keep finding the last significant number one after the another and check whether that number is equal to 0 or not.

int number, in , index , flag =0 ;

cout << " Enter a positive number count: ";
cin >> number;

index = number;

while(index > 0)
{

in = index % 10 ;
index = index / 10;

if (in == 0)
{cout << " Error! The number contains 0 in it ";
flag = 1;
break;
}
}

if(flag == 0 )
cout<<" the number does not 0 in it ";

above i have written simple code .
Since initially i focused only on getting the desired output i didn't tweak it much
u can still tweak it further and shorten the steps in it .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.