#include <iostream>
#include <sstream>
usingnamespace std;
int Persistent(int value)
{
int counter = 0;
while (value > 10)
{
int newvalue = 1;
int tmpvalue = value;
while (tmpvalue > 0)
{
// I get the last digit
int tmp = tmpvalue % 10;
newvalue *= tmp;
// last digit is cut
tmpvalue /= 10;
}
value = newvalue;
cout << "element: " << value << endl;
counter++;
}
return counter;
}
int main()
{
cout << "Please enter a Non - Negative Number";
int originalNumber = 715;
cout << "original number: " << originalNumber << endl;
cout << " number of element: " << Persistent(83);
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int number{ 0 };
cout << "Please enter a number (0-100)" << endl;
cin >> number;
while (number < 0 || number > 100)
{
cout << "Your input " << number << " is incorrect" << endl;
cout << "Try again" << endl;
cout << "Please enter a number (0-100)" << endl;
cin >> number;
}
return 0;
}
If you don't know how to use the while loop, then I recommend using the if statement. However, for the if statement, it will check for the wrong input and let the user know only once.