Looping Code not working

I have to have a looping code that does what the first part with the choices does and it was working until i moved onto adding the loop for the specific date part. If someone could help that would be amazing.

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  #include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{     
    string FirstLine="";
    //need an int variable
    int choicevariable = 0; 
   
    
   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;
   
   
   // i get stuck trying to figure out how to loop this part i know what parts i have to loop i am just not sure how.
   while (choicevariable < 1 || choicevariable > 3)
   {
     
   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;
       
       cin.clear();
     cin.ignore(100, '\n');
     } 
    
   
   
  
  
    
   //display thier choice
   cout << "#" << choicevariable << endl;
   
    if (choicevariable == 1) 
    while (choicevariable < 1 || choicevariable > 12)
    {   
        cout << "What is the Month?" << endl;
        int Month = 0;
        cin >> Month;
        
    while (choicevariable < 1 || choicevariable > 7)
           
        cout << "What is the Day?" << endl;
        int Day = 0;
        cin >> Day;
        
          
        int Year = 0;
        cout << "What is the Year?" << endl;
        if(!(cin >> Year)){
        
        
        cin >> Year;
        
        cout << " Ok, We will send you to" << endl;  
        
        cout << "Ending Program";
        
        cin.clear();
        cin.ignore(100, '\n');
        }
        
   
    
    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;
OK you have lots of {} issues going on you need to look over them and close them.

Line 50 & 56 while loops you are asking the user for a Month and a Day variable but you are checking it against your choicevariable?

Stick with a boilerplate while loop. Get condition, validate, ask again if invalid.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
		cout << "What is the Month?" << endl;
		cin >> Month;
		while (Month < 1 || Month > 12){
			cout << "Month is invalid, valid range 1 - 12. Enter again: " << endl;
			cin >> Month;
		}

		cout << "What is the Day?" << endl;
		cin >> Day;
		while (Day < 1 || Day > 7){
			cout << "Day is invalid, valid range 1 - 7. Enter again: " << endl;
			cin >> Day;
		}

		cout << "What is the Year?" << endl;
		cin >> Year;
		while (Year < 0){
			cout << "Year must be 0 or greater. Enter again: " << endl;
			cin >> Year;
		}


You are also going to run into some scope issues with your variables.
http://msdn.microsoft.com/en-us/library/b7kfh662(v=vs.110).aspx
http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.