this is what my program looks like but after prompting and reading my files, i get an infinite loop. the program compiles and i just put that simple cout statement just to see if anything will come out. can anyone see where i am messing up within my main that is causing this infinite loop?
#include <iostream>
#include <fstream>
#include <cstring>
#include <cctype>
#include <iomanip>
using namespace std;
const int MAX = 30;
const int MAX_HW = 10;
const int MAX_E = 3;
struct file1
{
int id;
string fname;
string lname;
int hw [MAX_HW];
int exam [MAX_E];
double exam_score;
double hw_score;
int totpts;
};
void fixstring (string&);
void get_data (file1 [], int&);
void alpha (file1 [], int);
void initial (file1 [], int);
void first (file1 [], int);
int main ()
{
string filename1;
string studentinfo;
string filename2;
string gradeinfo;
string filename3;
string results;
char ch;
char letter_score;
int x, x1, y, y1, z, z1;
double pct;
int id_temp;
int hw_score;
int exam_score;
int hw_num;
int exam_num;
file1 names [MAX];
//file2 grades [MAX];
ifstream inf1;
ifstream inf2;
ofstream outf;
int n = 0;
cout << "Please enter name of student information file:" << endl;
cin >> filename1;
cout << "Please enter name of grade information file:" << endl;
cin >> filename2;
cout << "Please enter name of output file:" << endl;
cin >> filename3;
inf1.open (filename1.c_str());
inf2.open (filename2.c_str());
outf.open (filename3.c_str());
inf1 >> names[n].id;
while (!inf1.eof())
{
inf1 >> names[n].lname >> names[n].fname;
fixstring (names[n].lname);
fixstring (names[n].fname);
n++;
inf1 >> names[n].id;
}
for (int hw_r = 0; hw_r < n; n ++)
{
for (int hw_c = 1; hw_c <= MAX_HW; hw_c ++)
{
names[hw_r].exam[hw_c] = 0;
}
}
for (int exam_r = 0; exam_r < n; exam_r++)
{
for (int exam_c = 1; exam_c <= MAX_E; exam_c ++)
{
names[exam_r].exam[exam_c] = 0;
}
}
inf2 >> id_temp;
while (!inf2.eof())
{
for (int x = 0; x < n; x ++)
if (id_temp == names[x].id)
{
inf2 >> ch;
while (ch != 'Q')
{
if (ch == 'H')
{
inf2 >> hw_num;
inf2 >> names[x].hw[hw_num];
}
else if (ch == 'E')
{
inf2 >> exam_num;
inf2 >> names[x].exam[exam_num];
}
inf2 >> ch;
}
}
inf2 >> id_temp;
}
for (int x = 0; x < n; x ++)
{
names[x].totpts = 0;
for (int hw_num = 1; hw_num <= MAX_HW; hw_num ++)
{
names[x].totpts = names[x].totpts + names[x].hw[hw_num];
}
for (int exam_num = 1; exam_num <= MAX_E; exam_num ++)
{
names[x].totpts = names[x].totpts + names[x].exam[exam_num];
}
}
alpha(names, n);
outf << right << setw (4) << "NAME" << setw (40) << "ID#" << endl;
for ( int x = 0; x < n; x ++)
{
//outf << names[n].fname << ", " << names[n].lname << names[n].id << endl;
outf << names[x].lname << ", " << names[x].fname << right << setw (40 - names [x].lname.length () - names\
[x].fname.length ()) << names [x].id << endl;
}
outf << endl <<endl;
outf.close ();
return 0;
}
void fixstring (string& names)
{
int wlen = names.length();
names[0] = toupper (names[0]);
for (int i = 1; i < wlen; i++)
names [i] = tolower (names[i]);
}
void alpha ( file1 names [], int n)
// Given the string "names", alpha will read in the file and place and arrange the names accordingl \
// y and put them in a particular order. The alphabetized array of strings will then be passed back.
{
int i;// initializing integer datatype to i
int j;// intiializing integer datatype to j
file1 temp;// string datatype being justified for temp to be used within function
for (i=0; i < n-1; i++)
{
for (j=0; j < n - (i+1); j++)
{
if (names[j].lname > names [j+1].lname)
{
temp = names[j];
names [j] = names [j+1];
names [j+1] = temp;
}
}
}
}
/*void initial (file1 names[], int n)
{
int x, q;
for (x = 0; x < n; x++)
{
cin >> names[n].id;
for (q = 0; q = 10; q++)
names[n].hw_num[q] = 0;
}
}*/