using functions

I am trying to create a program using Functions that will read a list of names and grades from a text file.That will also average the grades from highest to lowest in A's,B's,C's D's and F's this is what I have so far
the output will be:
Ace 95
Sam 90
Bill 75
Jim 65
Joe 45

There were 2 A's
there were 0 B's
there were 1 C
there were 1 D
there were 1 F

Highest: 95
Lowest: 45
Average 60



[code]
Put the code you need help with here.
#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std;

typedef char str[15];

void print(str names[], int grades[], int count)
{
for (int i = 0; i < count; i++)
cout << names[i] << setw(8)<< right << grades << setw(6) << left << endl;


}

void selectionsort(int names[],int count)
{

for (int i = 0; i < count;i++)
{
int largest = i;
for (int j = largest + 1; j < count; j++)
if (names[j]>names[largest])
largest = j;
int tmp = names[largest];
names[largest] = names[i];
names[i] = tmp;

}




}

float GetAverage(int grades[], int count)
{
float sum = 0;
for (int i = 0; i < count; i++)
sum += grades[i];
return sum / count;



}

float GetAverage(int names[],int count)
{
float sum = 0;
for (int i = 0; i < count; i++)
sum += names[i];
return sum / count;



}

int GetHighest(int grades[], int count)
{
int hi = grades[0];
for (int i = 1; i<count; i++)
if (grades[i]>hi)hi = g[i];
return hi;
}

int main(void)
{
str names[20];
int grades[20];
int i = 0;
char fn[30];

cout << "Enter file name"<<endl;
cin >> fn;
ifstream infile(fn);
if (infile)
{

for (; infile >> names[i] >> grades[i]; i++)
infile.close();

print(names, grades, i);
selectionsort(grades, i);

print(names, grades, i);
cout << endl;
}
}
Last edited on
Do you have a question or problem with your code?

Ran your code and your function GetHighest has a g unfinished which you probably forgot to finish writing grades also you have two functions that are exactly the same GetAverage. Other than that I could not finish the running since it requires a file.
Topic archived. No new replies allowed.