As the title says I am trying to pull info from a file, calculate GPA with file info, and display it on screen. I keep getting this weird output (below) and it is not showing the correct info. If anyone could help me figure out what is happening it would be greatly appreciated.
[output]
File Name: info1
Student's Name:
Student's Age: -13108
Student's SSN: -858993460
Student's Sex: ╠
Transfer Hours: -858993460 Transfer Quality Points: -858993460
MSU Hours: -858993460 MSU Quality Points: -858993460
-------------------
Transfer GPA: 1.00
MSU GPA: 1.00
Total GPA: 1.00
[correct info]
Name: Peter Ford
Age: 21
SSN: 789341256
Sex: M
Transfer hours: 10 Transfer quality points: 30
MSU hours: 48 MSU quality points: 179
[code]
struct Record {
char Sex;
short Age;
long SSN;
int hours, quality;
float GPA;
string Fname, Lname;
int totalhours, totalquality;
float totalGPA;
int MSUhours, MSUquality;
float MSUGPA;
};
void displayArecord(ofstream &myFileOut, Record Fname, Record Lname, Record age, Record SSN, Record Sex, Record hours, Record quality, Record GPA, Record MSUhours, Record MSUquality, Record MSUGPA, Record totalhours, Record totalquality, Record totalGPA)
{
Record record;
This kind of output mostly hints to a not initialized variable(s). This:
1 2 3 4 5
void displayArecord(ofstream &myFileOut, Record Fname, Record Lname, Record age, Record SSN, Record Sex, Record hours, Record quality, Record GPA, Record MSUhours, Record MSUquality, Record MSUGPA, Record totalhours, Record totalquality, Record totalGPA)
{
Record record;
record.GPA = (float)record.quality / record.hours;
So record is not initialized and there's no way for a useful result.
I guess what you want is this:
1 2 3 4 5
void displayArecord(ofstream &myFileOut, Record &record) // Note: Record &record as parameter
{
Record record;
record.GPA = (float)record.quality / record.hours;