While Loop
Ok I got my read file to read. Now for the last problem I am haveing a problem with my while loop...
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
|
int main()
{
ifstream filein;
filein.open("Undergrad.txt", ios::in);
filein.open("Grad.txt",ios::in);
ofstream fout;
const int SIZE = 10;
student*sPtr;
int Q=1;
int type;
char a,b;
unsigned long n=1;
while(a>b);{
{
cout << "\n";
cout << "\nPlease enter the file you would like to view:" << endl;
cout <<"\nEnter 1. for Graduate and 2. for Undergrad:\n" << endl;
cout << "\nEnter 5 to Quit\n";
cin >> type;
if(type==1)
{string words[SIZE];
fstream InFile;
InFile.open("Grad.txt" , ios::in);
for(int i=0;!InFile.eof(); i++)
{
InFile>>words[i];
cout<<words[i]<<" ";
}
InFile.close();
}
else if(type==2)
{
string words[SIZE];
fstream InFile;
InFile.open("Undergrad.txt" , ios::in);
for(int i=0;!InFile.eof(); i++)
{
InFile>>words[i];
cout<<words[i]<<" ";
}
InFile.close();
}
else if(type==5)
{cout<<"Program Closing"; n=0;}
else
{
cout << "\nComputer will now Self destruct\n";
system("pause");
n=0;
}
{
if((type==1)||(type==2))
{ sPtr -> input();
sPtr -> read_to_file(filein);
delete sPtr;
}
}
} while (n != 0);
filein.close();
getchar();
cin.clear();
return 0;
}
|
Where exactly do you initialize and/or modify a and b?
I am just wanting to create a forever loop till the person choses to exit
heres an updated version I'm having a problem when it runs to the end
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
|
int main()
{
ifstream filein;
filein.open("Undergrad.txt", ios::in);
filein.open("Grad.txt",ios::in);
ofstream fout;
const int SIZE = 100;
student*sPtr;
int Q=1;
int type;
char a,b;
unsigned long n=1;
do{
{
cout << "\n";
cout << "\nPlease enter the file you would like to view:" << endl;
cout <<"\nEnter 1. for Graduate and 2. for Undergrad:\n" << endl;
cout << "\nEnter 5 to Quit\n";
cin >> type;
if(type==1)
{string words[SIZE];
fstream InFile;
InFile.open("Grad.txt" , ios::in);
for(int i=0;!InFile.eof(); i++)
{
InFile>>words[i];
cout<<words[i]<<" ";
}
InFile.close();
}
else if(type==2)
{
string words[SIZE];
fstream InFile;
InFile.open("Undergrad.txt" , ios::in);
for(int i=0;!InFile.eof(); i++)
{
InFile>>words[i];
cout<<words[i]<<" ";
}
InFile.close();
}
else if(type==5)
{cout<<"Program Closing"; n=0;}
else
{
cout << "\nComputer will now Self destruct\n";
system("pause");
n=0;
}
{
if((type==1)||(type==2))
{cout <<"\n\n\nPress ENTER to exit the program....";
cin.get();
cin.get();
return EXIT_SUCCESS;}
}
} while (n != 0);
filein.close();
cout <<"\n\n\nPress ENTER to exit the program....";
cin.get();
cin.get();
return EXIT_SUCCESS;
}
|
Topic archived. No new replies allowed.