I have this so far, I need to be able to display the name and grade of the student with the highest grade. We have not covered arrays (which is what I have been seeing for this type of solution). Any advice would be appreciated. This is my first post, so please if I am doing this incorrectly, correct me.
int main ( void )
{
string name;
double grade, count, num, max, highestgrade;
count=1;
grade=max;
cout<< "Please Enter Number of Students: "<<endl;
cin >> num;
do
{
cin.ignore(100,'\n');
cout<< "Please Enter Students Name: "<< endl;
getline(cin, name);
cout<<endl<<"Please Enter Students Grade: "<<endl;
cin>> grade;
cout<<endl;
***UPDATE*** I pushed through and got the program to output the highest grade (whew, that was fun) but I need advice on what the best way to show the students name with the grade is. Here is my newest masterpiece.
int main ( void )
{
string name;
double grade, count, num, highestgrade;
count=1;
cout<< "Please Enter Number of Students: "<<endl;
cin >> num;
do
{
cin.ignore(100,'\n');
cout<< "Please Enter Students Name: "<< endl;
getline(cin, name);
cout<<endl<<"Please Enter Students Grade: "<<endl;
cin>> grade;
cout<<endl;
cout<<name << highestgrade;
That's fine, but you'll wanna add a few cout statements for clarity, like cout << "Student " << count << "is " << name << "and the highest grade is " << highestgrade << endl;
Also there's a problem regarding your while loop. Hint: it's at the very end.
YFGHNG, The program seems to run fine ( I have not added the clarity statements yet, just running sample runs for now)
Its just the name that prints in the cout statement at the end is the last name that was entered with the highest grade, even if the highest grade was associated with the first person entered. (Basically I am having trouble linking the names with the grades). Is the issue in my while loop statement you are referring to the reason why the program does this?
Oh I get what your problem is now. What you need are container classes. Basically anything like a vector, array, or dynamically allocated array. One string variable can only store just that: a collection of characters. If you want multiple Students, you're gonna need something to store all of them in.
That is what I thought. I have researched different approaches and the array is the popular answer, however, I'm not supposed to know how to use them yet (according to my class). Thank you for your help so far!