i am newbie in c++..
i have trouble in my program...
i confuses in this...why my program can't continue...just keep in main page...please help me..thank you
#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdlib> //declaration
#include<conio.h>
#include<string>
using namespace std;
int main()
{
int StudentAge,menu,choice,number;
string StudentIdNo, StudentCourse, StudentAddress;
char StudentName[25], StudentGender[1],StudentIcNo[15];
//Display main menu
cout<<"\n\n\n\n\n";
cout<<" =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.="<<endl;
cout<<" = !!COURSE REGISTRATION SYSTEM!! ="<<endl;
cout<<" = !!WELCOME TO METRO COLLEGE!! ="<<endl;
cout<<" = \t\t\t\\t\t\t\t\t\tDesign by Shirley Ng ="<<endl;
cout<<" =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.="<<endl;
cout<<"\n\n\n\n\n";
cout<<" ";
while (true)
{
do
{
cout<<" Please enter the follwing options:\n";
cout<<" \t1.ADD A NEW STUDENT RECORD\n";
cout<<" \t2.SEARCH STUDENT RECORD\n";
cout<<" 3.DELETE STUDENT RECORD\n";
cout<<" \t4.QUIT\n";
cout<<"Enter choice(1-4):";
output<<" New Student Profile\t"<<endl<<"Name:\t"<<StudentName<<endl;
output<<"ID:\t"<<StudentIdNo<<endl<<"Gender:\t"<<StudentGender<<endl;
output<<"Age:\t"<<StudentAge<<endl<<"IC no:\t"<<StudentIcNo<<endl;
output<<"Course:\t"<<StudentCourse<<endl<<endl;
if(StudentIdNo==StudentIdNo)
{
cerr<<"Student ID:"<<StudentIdNo<<"already contains information."<<endl;
}
cout<<"\n\nStudent Record has been save to file"<<endl<<endl;
system("pause");
cout<<"Do you want to go back menu?\n";
cout<<"1. Yes"<<endl;
cout<<"2 No"<<endl;
cin>>number;
if (number==1)
return main();
else
cout<<" Thank you for register"<<endl;
cout<<"Have A Nice Day"<<endl;
} break;
cout<<"Do you want to go back menu?\n";
cout<<"1. Yes"<<endl;
cout<<"2 No"<<endl;
cin>>number;
if (number==1)
return main();
else
cout<<" Thank you for register"<<endl;
cout<<"Have A Nice Day"<<endl;
}break;
case 3:
cout<<" Please Enter Student ID:"<<endl;
cin.ignore();
cout<<StudentIdNo<<endl;
{
ifstream input;
input.open("student file.txt");
while(!input.eof())
{
input>>StudentIdNo;
cout<<StudentIdNo<<endl;
}
system ("pause");
cout<<"Are you sure want to delete?\n";
cout<<" 1. Yes"<<endl;
cout<<" 2. No"<<endl;
cin>>number;
if(remove("student file.txt")==1)
{
cout<<"Data have been delele";
}
return 3;
input.close();
if(number==2)
return 0;
}break;
case 4:{
cout<<"\n\n\n";
cout<<"=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=";
cout<<" \t THANK YOU FOR REGISTER " ;
cout<<\t METRO COLLEGE!!\t ";
cout<<" HAVE A NICE DAY!! \t ";
cout<<"=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.= ";
menu=_getch();
while(menu==4);
return 0;
}break;
system("cls");
default:
cout<<"Please enter again"<<endl;
{
while(menu>5);
cout<<endl;
return main ();
}
}
}
}
#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdlib> //declaration
#include<conio.h>
#include<string>
usingnamespace std;
int main()
{
int StudentAge;
int menu;
int choice;
int number;
string StudentIdNo, StudentCourse, StudentAddress;
char StudentName[25];
char StudentGender[1];
char StudentIcNo[15];
//Display main menu
cout<<"\n\n\n\n\n";
cout<<" =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.="<<endl;
cout<<" = !!COURSE REGISTRATION SYSTEM!! ="<<endl;
cout<<" = !!WELCOME TO METRO COLLEGE!! ="<<endl;
cout<<" = \t\t\t\tDesign by Shirley Ng ="<<endl;
cout<<" =.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.="<<endl;
cout<<"\n\n\n\n\n";
cout<<" ";
while (true)
{
do
{
cout<<" Please enter the follwing options:\n"; //Get selection
cout<<" 1.ADD A NEW STUDENT RECORD\n";
cout<<" 2.SEARCH STUDENT RECORD\n";
cout<<" 3.DELETE STUDENT RECORD\n";
cout<<" 4.QUIT\n";
cout<<"Enter choice(1-4):";
menu = _getch();
}
while(false);
system("cls");
switch(menu){
case 1: //Create new student account
cout<<" =.=.=.=.=.=.=.=.=.=.=.=.=.=.=\tNew Student Profile=.=.=.=.=.=.=.=.=.=.="<<endl;
{
//create new file
ofstream output("student file.txt");
cout<<"Student Name:\t";
gets(StudentName);
cout<<"Student ID:\t";
cin>>StudentIdNo;
cout<<"Gender:\t";
cin>>StudentGender;
cout<<"IC No:\t";
cin>>StudentIcNo;
cout<<"Age:\t";
cin>>StudentAge;
cout<<"Student Course:\t";
cin>>StudentCourse;
output<<" New Student Profile\t"<<endl<<"Name:\t"<<StudentName<<endl;
output<<"ID:\t"<<StudentIdNo<<endl<<"Gender:\t"<<StudentGender<<endl;
output<<"Age:\t"<<StudentAge<<endl<<"IC no:\t"<<StudentIcNo<<endl;
output<<"Course:\t"<<StudentCourse<<endl<<endl;
if(StudentIdNo==StudentIdNo)
{ //when a ID aldready contains information can't using it
cerr<<"Student ID:"<<StudentIdNo<<"already contains information."<<endl;
}
cout<<"\n\nStudent Record has been save to file"<<endl<<endl;
system("pause");
cout<<"Do you want to go back menu?\n"; //return to menu
cout<<"1. Yes"<<endl;
cout<<"2 No"<<endl;
cin>>number;
if (number==1)
return main();
else
cout<<" Thank you for register"<<endl;
cout<<"Have A Nice Day"<<endl;
} break;
case 2:
cout<<" =.=.=.=.=.=.=.=.Search Student Record=.=.=.=.=.=.=.=.=.=.=.="<<endl;
//Search student record when keyin ID number
cout<<endl;
cout<<"Please Enter Studend ID:"<<endl;
cin>>StudentIdNo;
cin.ignore();
{
ifstream input ("student file.txt"); //read the information
while(!input.eof())
{
input>>StudentIdNo;
cout<<StudentIdNo<<endl;
}
input.close();
system("pause");
cout<<"Do you want to go back menu?\n";
cout<<"1. Yes"<<endl;
cout<<"2 No"<<endl;
cin>>number;
if (number==1)
return main();
else
cout<<" Thank you for register"<<endl;
cout<<"Have A Nice Day"<<endl;
}break;
case 3: //Delete student account
cout<<" Please Enter Student ID:"<<endl;
cin.ignore();
cout<<StudentIdNo<<endl;
{
ifstream input;
input.open("student file.txt");
while(!input.eof())
{
input>>StudentIdNo;
cout<<StudentIdNo<<endl;
}
system ("pause");
cout<<"Are you sure want to delete?\n";
cout<<" 1. Yes"<<endl;
cout<<" 2. No"<<endl;
cin>>number;
if(remove("student file.txt")==1)
{
cout<<"Data have been delele";
}
return 3;
if(number==2)
return 4;
input.close();
}break;
case 4:{ //Quit the program
cout<<"\n\n\n";
cout<<"=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.= ";
cout<<" \t THANK YOU FOR REGISTER ";
cout<<" \tMETRO COLLEGE!! ";
cout<<" HAVE A NICE DAY!! ";
cout<<"=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=.=. ";
menu=_getch();
while(menu==4);
return 0;
}break;
default:
cout<<"Please enter again"<<endl;
{
while(menu>5);
cout<<endl;
return main ();
}
}
}
}
//end of program
You are missing a '{' on your else statement...also, do NOT EVER rescursively call main() (e.g. call it inside of itself like you are on line 5 of that snippet)