Hi there guys I am having trouble with a particular input in my program. If you will run my program and enter the word "IT" in Enter Course, it loops and jumps to do you wish to return to the main menu. Please use Microsoft Visual C++ 6.0 Professional Edition in testing my code to be able to see my problem/
Here is my code: (Note* the line on red font is the ones im having trouble with)
#include<iostream>
#include<string>
#include<windows.h>
#include<fstream>
#include <iomanip>
#include<cctype>
#include<cstdlib>
#include <ctype.h>
using namespace std;
struct TF
{int units, punits, misc;};
struct studre
{
char choice;
string Sno;
string Fname;
string Mname;
string Sname;
string course;
int year;
int fees;
};
void ClearScreen();
void input();
int main()
{
int tuitiontotal;
int i;
int totalunits;
studre level[100];
int x;
studre record[1000];
TF amount[100];
TF tuition;
tuition.punits=800;
tuition.misc=2000;
char choice;
ofstream output;
while(true)
{
cout<<"Enter number of students that will enroll (Max. of 5 students only)"<<endl;
cin>>x;
try
{
if(x>5||x<1)
{
throw x;
}
}
catch(int a)
{
ClearScreen();
cout<<"Invalid input. Please try again."<<endl;
continue;
}
output.open("record.txt", ios::app);
output<<"Enrollment and Tuition Fee Record"<<endl;
output<<endl;
output<<"Total Students: "<<x<<endl;
output<<endl;
output.close();
for (int i=0;i<x;i++)
{
cin.ignore();
try
{
cout<<"Student Number"<<"["<<i+1<<"]: "<<endl;
getline(cin,record[i].Sno);
if(record[i].Sno.length()>10||record[i].Sno.length()<10)
throw record[i].Sno;
}
catch (string g)
{
while(record[i].Sno.length()>10||record[i].Sno.length()<10)
{
{
ClearScreen();
cout<<"Invalid input. Enter a 10 digit nuumber"<<endl;
}
getline(cin,record[i].Sno);
}
}
cout<<"Enter First Name"<<"["<<i+1<<"]: "<<endl;
getline(cin,record[i].Fname);
cout<<"Enter Middle Name"<<"["<<i+1<<"]: "<<endl;
getline(cin,record[i].Mname);
cout<<"Enter Last Name"<<"["<<i+1<<"]: "<<endl;
getline(cin,record[i].Sname);
cout<<"Enter Course"<<"["<<i+1<<"]: "<<endl;
cin>>record[i].course;
cout<<"Enter Year"<<"["<<i+1<<"]: "<<endl;
cin>>level[i].year;
cout<<"Enter Units"<<"["<<i+1<<"]: "<<endl;
cin>>amount[i].units;
totalunits+=amount[i].units;
ClearScreen();
}
cout<<"Total Number of Students Enrolled: "<<x<<endl;
tuitiontotal=(totalunits*tuition.punits)+(tuition.misc*x);
cout<<"Total Tuition Fee is:"<<"Php "<<tuitiontotal;
cout<<endl;
for (int j=0;j<x;j++)
{
output.open("record.txt", ios::app);
output<<"Student Number"<<"["<<j+1<<"]: "<<record[j].Sno<<endl;
output<<"First Name"<<"["<<j+1<<"]: "<<record[j].Fname<<endl;
output<<"Middle Name"<<"["<<j+1<<"]: "<<record[j].Mname<<endl;
output<<"Last Name"<<"["<<j+1<<"]: "<<record[j].Sname<<endl;
output<<"Course"<<"["<<j+1<<"]: "<<record[j].course<<endl;
output<<"Year"<<"["<<j+1<<"]: "<<level[j].year<<endl;
output<<"Units"<<"["<<j+1<<"]: "<<amount[j].units<<endl;
output<<"Tuition"<<"["<<j+1<<"]: "<<((amount[j].units)*(tuition.punits))+tuition.misc<<endl;
output<<endl;
output.close();
}
output.open("record.txt", ios::app);
output<<"Total Tuition Fee for "<<x<<" students:"<<"Php: "<<tuitiontotal<<endl;
output<<"End of Record"<<endl;
output.close();
while(choice!='Y'&&choice!='N')
{
cout<<"Do you wish to return to the Main Menu?(Y/N):";
cin>>choice;
ClearScreen();
choice=toupper(choice);
}
if(choice=='Y')
{
main();
}
else if(choice=='N')
exit(1);
system ("pause");
return 0;
}
}
void ClearScreen()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi ))
return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
SetConsoleCursorPosition( hStdOut, homeCoords );
}
Anyone there who has a fix for this??? Help me please...