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.
*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);
}
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.