Help with Looping

Hello. I missed a couple days of work being sick and am completely lost on what to do for my assignment. I have read some tutorials and am still stuck on how to initiate and get a loop to run. If you could help that would be amazing. Thanks

Your program should continue to function as before, showing different options depending on what they selected. Most likely you will not need to change the if/else part of your logic. The difference is now, if they do not choose 1, 2 or 3 it must keep asking them to input 1, 2 or 3 for the main menu.

In this section of the program it must keep looping until the user enters a value from 1 to 12 for the month. Another loop will be used to get the day - a value between 1 to 31, and another loop for the year. The year cannot be a letter, it must be a number. But you do not need to specify a minimum and maximum value unless you want to.

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 must use a loop to validate that a 1, 2, 3 or 4 has been entered before the program continues.

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.

In summary, your program will end up with these 5 or 6 loops:
Main menu options (1, 2 or 3)
Month (1-12)
Day (1-31)
Year - a number
Time Periods menu (1, 2, 3 or 4)
Optional (5 points extra credit) - make the entire program loop so you can pick another option.

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  #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 << endl;
   
    if (choicevariable == 1) {
        cout << "What is the Month?" << endl;
        int Month = 1 - 12;
        cin >> Month;
        
        cout << "What is the Day?" << endl;
        int Day = 1 - 31;
        cin >> Day;
        
        cout << "What is the Year?" << endl;
        int Year = 0;
        cin >> Year;
        
        cout << " Ok, We will send you to" << endl;  
        
        cout << "Ending Program";
        
   }
    
    if (choicevariable == 2)
    
    
     {
            int timePeriod;              
        cout << "Choice from one of the time periods:" << endl << endl;
        
        cout << "1. Prehistoric Dinosaur Era" << endl;
        cout << "2. Pirate Era" << endl;
        cout << "3. Five Days ago" << endl;
        cout << "4. Mideval" << endl;
        
        cin >> timePeriod;
        cout << " Ok, We will take you to" << timePeriod << endl; 
        
        cout << "Ending Program";                      
   }                   
   
   if (choicevariable == 3)
   
      {
       cout << "Ok, I'll choose where to send you" << endl;                
      }                
      
      
      
   else if (choicevariable > 3)
    
    cout << "Choice Not Valid" << endl;
    cout << "Ending Program" << endl;                     
    
    system("PAUSE");
    return EXIT_SUCCESS;
I think you forgot the loop you wanted to run, whether it be a for loop, a while loop, or a do-while loop.
I forgot the loop because i forgot how to write the code for a loop. if u read the top it tells you have has to be done and what has to loop but i do not know how to write the loop code.
1
2
3
4
5
6
7
8
9
10
11
12
for ( init-expression(int i=0); cond-expression(i<10) ; loop-expression(i++) )
{
statement;
}


    init-expression i = 0
    while(i<10){
        statement;
        i++;
    }
Last edited on
Topic archived. No new replies allowed.