I have a simple assignment that makes my head spin. (I guess I'm not quite there yet.)
I must build a program that asks for 20 records. Each record holds a first and last name, and a test score. It then figures out the grade letter for the test score and then outputs all the data that was entered; also finding the highest score amongst the 20 test scores.
To do this I must use a struct to hold the data and four functions to do all the work. So that main pretty much does nothing.
(the book is no help. I hate it.)
My first problem is that when I run a basic version of the program (I made a program just to read 1 record and read it back out to me.), it doesnt keep the first and last name data. It keeps testscore and grade data. But for some reason it's not keeping any name data I input and I can't figure out why
Here's the code I've written:
Code:
#include<iostream.h>
#include<conio.h>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;
struct studentType
{
string FName;
string LName;
int testScore;
char grade;
};
int main()
{
void studentData();
void getGrade();
void highestScore();
void printData();
studentData();
getGrade();
highestScore();
printData();
getch();
}
void studentData()
{
studentType student;
cout<<"Hey"<<endl;
cin>>student.FName>>student.LName;
cin>>student.testScore;
}
void getGrade()
{
studentType student;
if (student.testScore >= 90)
student.grade = 'A';
else if (student.testScore >= 80)
student.grade = 'B';
else if (student.testScore >= 70)
student.grade = 'C';
else if (student.testScore >= 60)
student.grade = 'D';
else
student.grade = 'F';
}
void highestScore()
{
cout<<"Hi!"<<endl;
}
void printData()
{
//Last name, First Name, Score, Grade
studentType student;
cout<<student.LName<<", "<<student.FName<<" : "<<
student.testScore<<" : "<<student.grade;
}
If anyone could just help me out here. All I need is a little push in the right direction. I'm not asking for you to do the entire work for me. I just need to get over this bump in the road.
-What's wrong with the program; Why wont my name data carry over.
-How would I eventually incorporate an array into this to input and hold 20 records of student data?