First Project- Switch case infinite loop/possible if statement trouble.

I have to create a project to get a students info and use strings and structures and can't figure out how to get out of this infinite loop. case 1 is for entering the student info were case 4 will be the Option to quit but the while loop should do everything but case 4 and I am not sure if i have the call menu function in the wrong place or whats going on with it.

Any help would be appreciated.

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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
 *BEGIN Transcript
 * Call menu function 
 * WHILE(menu choice isn't quit)
 *      SWITCH (Menu choice)
 *         CASE 1:
 *            Call student info function
 *         CASE 2:
 *            Call coarse info function
 *         CASE 3:
 *            Call Calc GPA function
 *            Call Display function
 *      END SWITCH
 *      IF(student name = quit)
 *         menu choice = quit value
 *      ELSE
 *         Call menu choice  
 *      END IF   
 *   END WHILE
 *END Transcript
 *********************************************************************/

#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;

//Programmer defined data types
struct student
{
	string Student_Name;
	int Id;
};

//prototypes
int menu             (int);
student student_info    ();  // Function to get Player data 

int main()
{
	//local constants
	
	//local variables
    int Option; 
	student One_Student; // Initializes One Player  
	
	/**************************start main program*********************/
    
    Option = menu (Option); // Calls Function for Menu 
    
    while (Option != 4)
    {
    	switch (Option)
	    {

	       case (1):
		   {
		     
			 One_Student = student_info();  	
		     break;
	
		   }
		  
		   case (2):
		   {
		
		     
		      break;  
		   
		   } 
		 
		   case (3):
		   {
		  

		      break;	 
		     
		   } 	          
	    
         
	    }

	
	       Option = menu (Option); // Calls Function for Menu		
			
	}
    
   
}//end main program

/********************************************************************

*BEGIN Menu
*   Display 1. enter student info
*   Display 2. enter coarse info
*   Display 3. calc gpa and display all info
*   Display 4. exit program
*   Get menu choice
*   Retunr menu choice
*END Menu   
********************************************************************/					
int menu (int Option)
{
	//local constants
	
	//local variables
	
	/*********************************************/
    
    //Prompt for Employee's Name
	cout << "\n\n\n\n\n\n\n";
	cout << setw(52) << "-----------------------------" << endl;
	cout << setw(52) << "1): Enter Student's Info"      << endl;
	cout << setw(52) << "2): Enter Course Info"         << endl;
	cout << setw(52) << "3): Display Student"           << endl;
	cout << setw(52) << "4): Exit"                      << endl;
	cout << setw(52) << "-----------------------------" << endl;
	cout << "\n" << setw(34) << "Option: ";
	cin  >> Option;	
	 
	return (Option);
}

/********************************************************************

 ********************************************************************/
student student_info()
{
	//local constants
	
	//local variables
    student One_Student; 
	/*********************************************/
    
    // Prompt for Full Name, Number of Goals and Assists. 
    
    // Prompt for Full Name, Number of Goals and Assists. 
	cout << "Enter Student's Name: ";
	cin  >> One_Student.Student_Name;
    
    // Return the Player's Data
    return (One_Student); 
}	
Bump..
Line 1: You're missing an opening /

Line 21: You need to include the <string> header.

Line 48: There is no need to pass option to menu. The passed value is not used and the compiler gives a warning that option is not initialized.

Line 101: option should be a local variable. There is no reason to pass it in as an arguement.

Under what conditions does your program loop? I entered 1 and it prompted me for a strudent name. I entered a 4 and it quit. After fixing your compile errors. I don't see a problem.

Under what conditions does your program loop? I entered 1 and it prompted me for a strudent name. I entered a 4 and it quit. After fixing your compile errors. I don't see a problem.


after the changes i figured out that using a space will trigger it to go into a infinite loop.

Thank you for the help.
Last edited on
Topic archived. No new replies allowed.