persistence how to make user input

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;
}

how would i make this where the user puts in a number instead of having a default number
You ask the user for the value:
1
2
3
4
5
6
7
8
int main()
{
    int originalNumber = 83;
    cin >> originalNumber;
    cout << "original number: " << originalNumber << endl;
    cout << " number of element: " << Persistent(83);
    return 0;
}
closed account (1vD3vCM9)
What is #include <sstream> ?
Can you please explain me so I'll learn it? ^^
closed account (1vD3vCM9)
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
closed account (48T7M4Gy)
What is #include <sstream> ?
Can you please explain me so I'll learn it?

http://www.cplusplus.com/reference/sstream/stringstream/stringstream/
closed account (48T7M4Gy)
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.
Topic archived. No new replies allowed.