I need to keep track of students last names and their GPAs. I need the user to enter 7 names and their GPA. I need to output it in columns. Also I need the average GPA and the Highest GPA. And I also need 'Last Name' earned the highest GPA.
This is what I have. PLEASE HELP

int main()
{
	int nameArray[7], gPAArray[7];
	double averageGPA=0, highGPA=0, gpa;
	ofstream out;

	out.open("g:\\StudentGPAOut.txt");

	cout<<"please enter your last name. ";
	cin>>nameArray[7];
	cout<<endl;

	cout<<"please enter your GPA(0-4.0 scaled). ";
	cin>>gPAArray[7];
	cout<<endl;

	out<<fixed<<showpoint;
	out<<setprecision(2);

	
	out<<setfill('.')<<left<<setw(18)<< "Last Name: "
		  <<right<< " "<< "GPA: "<<endl;
	
	out<<setfill('.')<<left<<setw(18)<<nameArray; 
	out<<right<< " "<<gPAArray<<endl;


	out<<"Last Name earned the highest GPA.";

	out.close();

return 0;
}

Recommended Answers

All 6 Replies

You can't store names in an int-array. Int is for numbers only. You should use strings.
Here's a sample program that takes in 7 names and shows them.

#include <iostream>
#include <string>

using namespace std;

int main()
{
    const int size = 7;
    string names[size];  
    //get seven names
    for (int i = 0; i < size; i++)
    {
        cout << "enter name for person " << i << "\n";
        getline(cin,names[i]);
    }

    //now show the names
    for (int j = 0; j < size; j++)
       cout << "Person " << j << " = " << names[j] << "\n";
    cin.get();
    return 0;
}
commented: Good post. +3

How do I Get the GPs to get in the system

do the same thing only now with a double array. double gpa[size] ;


But now use cin >> gpa[i] instead of getline(). Getline only works with (c)strings.

like This

double gpa[size];
for (int i2=0; i2<gpa[size]; i2++)
        {
            cout << "enter name for person "<<i<<endl;
            cin>>gpa[i2]);
        }

        for (int j2 = 0; j2 < size; j2++)
        cout << "Person "<<j2<< " = "<< names[j2]<<endl;
        cin.get();

I used i2 and j2 because they repeated, but there are still 8 errors

No. More like:

const int size = 7;
    string names[size];  
    double gpa[size];
    //get seven names and gpa's
    for (int i = 0; i < size; i++)
    {
        cout << "enter name for person " << i << "\n";
        getline(cin,names[i]);
        cout << "enter GPA for person " << i << "\n";
        cin >> gpa[i];
        cin.ignore();
    }

I'll leave the "show data loop" to you as well as calculating the avarage. I'm not going to do your homework of course ;)

Be sure you add some error-checking for the input :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.