User input and output help

Write your question here.

Hello Everyone,

My professor just gave us an assignment to create a Time Machine Program That takes the persons name and outputs it saying "playername" "welcome to the time machine" then give the person 3 options to get started with. I am not sure how to get the users input on the option and output the responce saying - "#1, 2, or 3 Excellent Choice". Thank you for your help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  #include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    string FirstLine="";
    //need an int variable
   
   cout << "Welcome to The Time Machine" << endl << endl;
   cout << "What is your Name?";
   
   getline(cin, FirstLine); 
  
  //display user's name
   cout << "HI " << FirstLine << endl << endl;
  cout << "Select an option to get started:" << endl;
   
   cout << "1. Enter a Specific Date" << endl;
   cout << "2. Select a Time Period" << endl;
   cout << "3. Wildcard - I'm Feeling Lucky" << endl << endl;
   
   //get the user's choice using your int variable and cin
   
   //display thier choice
   cout << choicevariable << " excellent choice" << endl;     
    
    system("PAUSE");
    return EXIT_SUCCESS;
Initialize 'choicevariable' first-
1
2
//need an int variable
int choicevariable;


Then in main(), use this-
1
2
3
//get the user's choice using your int variable and cin
cout<<"Enter your choice: ";
cin>>choicevariable;


Then display like this-
1
2
 //display thier choice
cout << "#" << choicevariable << " excellent choice" << endl;
Last edited on
Then you may want to use a switch statement and do different things based on option 1 , 2 or 3.

1
2
3
4
5
6
7
8
9
switch( choicevariable )
{
    case 1:
        //do stuff
        break;
    case 2: //do stuff and break
    case 3: //do stuff and break
    default: //do stuff
}
Thank you. It now works.
Topic archived. No new replies allowed.