When this program runs, I can enter in the name the first time through the while loop (using "cin.getline). When I go through the second time, it skips the name and asks to enter the ss#.
The first time through, everything works fine.
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
struct student_rec
{
char name[30];
char ss[9];
int grade_3cr[4];
int grade_1cr[1];
};
void initializeStudent (student_rec &any_student)
{
any_student.name[30] = ' ';
any_student.ss[9] = ' ';
any_student.grade_3cr[0] = 0;
any_student.grade_3cr[1] = 0;
any_student.grade_3cr[2] = 0;
any_student.grade_3cr[3] = 0;
any_student.grade_1cr[0] = 0;
}
void processStudent (student_rec &your_student, const int& CREDIT_3, const int& CREDIT_1)
{
cout.setf(ios::fixed);
int i = 0,
tot_credits = 0,
tot_grade = 0;
float gpa;
cout<<setw(15)<<your_student.name
<<setw(15)<<your_student.ss
<<" ";
for (i=0;i<=3;i++)
{
cout<<setw(3)<<your_student.grade_3cr[i]
<<" ";
tot_grade = tot_grade + (your_student.grade_3cr[i] * CREDIT_3);
tot_credits += CREDIT_3;
}
cout<<setw(8)<<your_student.grade_1cr[0]
<<endl<<endl;
tot_grade = tot_grade + (your_student.grade_1cr[0] * CREDIT_1);
tot_credits += CREDIT_1;
gpa = tot_grade / tot_credits;
cout<<"Students total credits this senester is "
<<tot_credits<<endl<<endl;
cout<<"students overall gpa is "
<<setprecision(2)<<gpa<<endl<<endl;
}
int main()
{
/*--------------------------------------
* Initialize variables
*------------------------------------*/
int i,
rec_cnt = 1;
const int CREDIT_3 = 3;
const int CREDIT_1 = 1;
const int STUDENTS_IN_CLASS = 2;
student_rec your_student;
student_rec first_student;
student_rec second_student;
initializeStudent(first_student);
initializeStudent(second_student);
cout<<"\n\n ....... Student Records ....... \n\n";
while (rec_cnt <= STUDENTS_IN_CLASS)
{
initializeStudent(your_student);
cout<<" Enter in Name of Student: ";
cin.getline(your_student.name, sizeof(your_student.name));
cout<<"\n Enter in Student SS#: ";
cin>>your_student.ss;
cout<<"\n Enter in Students Four 3 Cedit Gades: ";
for (i = 0;i<=3;i++)
cin>>your_student.grade_3cr[i];
cout<<"\n Enter in Students Single 1 Credit Grades: ";
i = 0;
cin>>your_student.grade_1cr[i];
if (rec_cnt == 1)
first_student = your_student;
else
second_student = your_student;
rec_cnt++;
}
system ("CLS");
cout<<"Student Name Soc. Sec. No. 3 Credit Grades 1 Credit Grade\n"
<<"--------------- -------------- ---------------- --------------\n"
<<endl<<endl;
initializeStudent(your_student);
your_student = first_student;
processStudent (your_student, CREDIT_3, CREDIT_1);
initializeStudent(your_student);
your_student = second_student;
processStudent (your_student, CREDIT_3, CREDIT_1);
system("PAUSE");
return 0;
}
As always, I appreciate your help:)
Bob