Homework

This is the description of that i have to do --- Time Machine if-else
You will be adding on to your Time Machine program. It might be useful for you to use the copy you submitted for the Time Machine variables lab assignment and begin building it from the code you already started.

It must still ask the user for their name and display a welcome message using their name. Then display the three options:

1. Enter a Specific Date
2. Select a Time Period
3. Wildcard - I'm Feeling Lucky

After the user makes a selection, use ONE if/else if selection structure to display different options based on their input.

For choice number 1 you must get the month, day and year and display their selection back on the screen. (So that means you will need variables for month, day and year).

1. Enter a Specific Date
What is the month? (enter 1-12)
What is the day? (enter 1-31)
What is the year?
Ok, we will send you to month/day/year

For choice number 2, you can be creative with the time periods. But it should display back their choice. So you will need a variable for the time period.

2. Select a Time Period
Choose from one of these time periods.
1. Prehistoric Dinosaur Era
2. 500 BC
3. Renaissance
4. American Civil War
Ok, we will send you to choice number __

For choice number 3, you can make up a simple response.

3. Wildcard - I'm Feeling Lucky
Ok, I'll choose where to send you.

Also setup your if/else structure so that if the user doesn't pick 1 or 2 or 3 to display a message that the choice was not valid.

Finally, end the program with a message that says the time machine program is ending.

--- I forget personally how to do the if else if code and i have to do 3 different sections of it. Please help and if you know any places i can read up on stuff please share. All is apreciated.

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
32
33
34
  #include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    string FirstLine="";
    //need an int variable
    int choicevariable;
   
   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
   cout << "Enter your choice: ";
   cin >> choicevariable;
   
   //display thier choice
   cout << "#" << choicevariable << " excellent choice" << endl;     
    
    system("PAUSE");
    return EXIT_SUCCESS;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if (/*condition*/)
{
//do something
}

//will only run if the previous if statement was false
else if (/*condition*/)
{
//do something else
}
//will only happen if all other if/else if statements are false
else
{
//do something else
}
Topic archived. No new replies allowed.