I have a couple of general questions for my program

#include <iostream>
using namespace std;
int main ()
{
cout << "In this program, you are going to be asked to pick a number between 1 and 10, but your not going to tell the program that number yet. Instead this program will ask you to perform certain tasks. Once all of these tasks are completed, the program will predict what your final answer is. Press enter to start the program \n";
cout << "Think of a number between 1 and 10. Once you have thought of one press enter to proceed to the next step \n";
cout << "Next I want you to take this number and double it. Press enter for the next step \n;
cout << "Add 4 to this number, then press enter when you are ready for the next step \n;
cout << "Now divide it by two. One more step to go! Press enter when you are ready \n;
cout << "Your last step is to subtract this number by the number you originally chose. Press enter to see your answer \n";
cout << "Your final answer is 2 \n";
return 0;
}

Okay so I have 2 general questions about this program. First off when I run it, it spits out all of this at once. How do I make it so that the first sentence appears, then the next cout will appear when they press enter?

My second question is whats the simplest way to write a program like this so that it can always predict or read peoples minds like my example?
1. You can use cin.ignore to wait for the next line
cin.ignore(numeric_limits<streamsize>::max(), '\n');

2. Think about what is happening. The user thinks about a number X.
Double it: 2 * X
Add 4: 2 * X + 4
Divide by 2: (2 * X + 4) / 2 = X + 2
Subtract X: X + 2 - X = 2
So the trick is to end up with a number that has nothing to do with X.
Last edited on
Topic archived. No new replies allowed.