how would i make this where the user puts in a number instead of having a default number
#include <iostream>
#include <sstream>
using namespace 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()
{
int originalNumber = 83;
cout << "original number: " << originalNumber << endl;
cout << " number of element: " << Persistent(83);
return 0;
}
And yes. To ask for input you can use cin >> originalNumber;
Although I guess you are a begginer. I DONT recommend typing using namespace std; as its not so good and can cause problems.
If you listen to my advice, and remove you, you will have to put std:: in front of every cout or cin.
Like std::cin >> originalNumber;
You young grass Hooper, you have a lot to learn.
Good luck :D
If you listen to my advice, and remove you, you will have to put std:: in front of every cout or cin.
1 2
using std::cout;
using std::cin;
...
is another way of avoiding the very general using namespace std while at the same time avoiding the need to type std:: everywhere and the obscurity that comes with such precision. Grasshoppers can often skin cats many ways, not just one.