I'm now stuck on trying to figure out why my letterGrade function isn't working....I'm trying to take the numerical values found right before it, in the Avg colum, and turn it into a letter grad (which I assume needs to be as a string).

Any suggestions?

Total Number of Students: 73
 ID      LName      FName          Q1   Q2   Q3   MT   Q4   Q5   Q6    F   Avg  Grade
-------------------------------------------------------------------------------------
45256   Rodrigues   Joana          58   75   58   61   59   75   63   92  66.2    F
37915   Wright      Michelle       98   83   56   62   63   90   57   67  62.6    F
81984   Williams    Jenny          55   67   54   63   89   84   93   75  66.0    F
73984   Phaneuf     Lesley         78   85   57   51   68   94   51   83  65.1    F
80886   Laflamme    Nicole         76   51   71   94   69   78   87   91  74.3    F
39473   Kenyon      Patricia       65   54   90   68   94   70   95   97  75.5    F
12127   McCabe      Kelly          51   96    0   64   54   75   71   94  60.1    F
52458   Whitten     Sarah          99   58   94   82   81   75   82   70  69.5    F
77921   Connors     Sarah          52   58   88   63   61   65   78   78  64.5    D-
28810   Navin       Joshua         94   75   62   93   64   92   87   94  78.8    D-
31571   Toporowski  Crystal        93    0   77   77   63   68   88   58  56.7    D-
33580   Ziolko      John           74   64   98   92   98   89    0   79  67.8    D-
14508   Stronach    Kurt           80   95   96   84   78   86   53   59  68.6    D-
44520   Ecklord     Ryan            0   61   56   86   98   98   59   83  72.1    D-
15246   Berling     Danielle       85   64    0   75   69    0   54   85  55.7    D-
16137   Littlefield Arionna        71   85   74   97   69   64   82   95  75.2    D-
62631   Niedojadlo  Evan           73   66   83   97   97   51   66   88  72.5    D-
59640   Knieriem    Brandon        52   87   97   66   97   90   93   56  69.5    D-
44102   Spence      Arthur         85   84  100   82   91    0   95   62  65.7    D-
42331   Rose        Nicole         83   50   96   68   54   62    0   93  64.2    D-
72054   Houde       Jessica        72   66   71   62   75   71   86  100  78.6    D-
24609   Cooper      Camille        62   93   92   72   58   76   57   66  65.6    D-
85736   Hepburn     Spencer        71    0   62   60   52   62   64   51  46.6    D-
87129   Morang      Nicholas       77   67   57   89   88   64   68   78  69.6    D-
43865   Hildebrandt Stephenson     97   94   93   93   82   88   78  100  85.1    D-
78575   Suslovic    Vikilynn       65   54   74   67   61   76   69   76  63.3    D-
58751   Flores      Jose           58   80    0   74   87   95   96   69  62.8    D-
18140   Galotti     Salvator       78   65   90   66   88   57   93   98  75.5    D-
10364   Denaro      Tony           73   85   55   72   68   91   55   89  68.5    D-
99189   Vasquez     Oskar          66   60    0   75   63   92   92   52  56.3    D-
21705   Roy         Jake           86    0   89   94   82    0   60   98  64.8    D-
50838   Burr        Jermiah        83   84   94   90   77   73   72   63  77.5    D-
32998   Benway      Eileen         76   98   80   69   75   94   77   95  76.6    D-
87361   Perlmutter  Diadre         96   60   81   88   81   53   91   74  70.2    D-
61084   Cruz        Waldemar       70   68   76   87  100   80   92   86  77.1    D-
54378   Franco-BanksNixaliz        99   58   80   66   63   59   98   83  67.2    D-
10984   Juste       Kerlande       97   73   98   86   96   73   68   57  77.1    D-
77463   Weber       Jessica        60   56   77   62   81   74   78   69  63.4    D-
36278   Hartman     Kristine      100   62   71  100   69   51   58   55  61.5    D-
94304   Bowdy       James           0   57   70  100   92   84   50   98  77.0    D-
55937   Kantzios    Angela         55    0   78   86   93   73   82   76  66.0    D-
17600   DeNinno     David          62   68   93   88   84   60   98   75  70.7    D-
28248   Courville   David          81   88   89   52   64   79   89   87  69.6    D-
61316   Eaton       John           80   51   93   67   90   92   76   69  67.5    D-
84511   Calluari    Henry          72   84   97   59   73    0   86   74  63.0    D-
39234   Spaulding   Nicholas       61    0   76   90   92   53   75   54  58.0    D-
33068   King        Nicholas       70   83   83   89   51   98   75   70  69.5    D-
45403   Breault     Matthew        52   75   70   64   91   59   57   94  69.3    D-
29303   Morales     Lynaska        65   56   97   65   98   73   99   76  71.0    D-
28432   Calle       Juan          100   51   51   65   69   59   68   90  63.5    D-
85434   Hagen       Amanda         72   90   99   71   87    0   81   98  72.2    D-
79998   Szostak     Patrycja       58   67   56   68   77   96    0   81  59.6    D-
19374   Gurung      Manoj          98   85   92   93   85   95   93   99  84.8    D-
46103   Shaw        Lindsay        97   85   85   89   64   57   89   73  71.4    D-
13009   Palko       Michael        98   82   92   51    0   80   73   88  63.5    D-
55698   Reyes       Joselina       59   81   53   90   80   94   79   93  74.9    D-
64779   Alba        Sasha          55   67   93   64    0   91   92   55  54.4    D-
86071   Aimetti     Sean           51   83   88   98   91   83   75   66  74.0    D-
33205   Roberts     Thomas         86   94   70   88   64   88   64   87  75.7    D-
81233   Procko      Nancy          69   51   57   80   52   66   61   51  54.5    D-
90219   June        Christopher    66   86   80   60   71    0   76   80  61.7    D-
39285   Calluari    Joel           77   57   71   78   58   94   71   75  66.5    D-
44686   Soulliere   Jane           69   55   80   95   67   76   89   62  67.5    D-
51785   Kokoszka    Elizabeth      71   61   77   83    0   96   84   56  58.7    D-
26789   Irizarry    Elsie          87   77   76   68   65  100   95   79  72.5    D-
11371   Berry       Angela         90   77   54   76   90   64   97   77  70.7    D-
92521   Cyr         Gregory        59   86   97   85   59   62    0   72  62.7    D-
90742   Manfredi    Kathryn        94   65   81   90   67   66   79   52  71.6    D-
71831   Oquendo     Jessica        60   60   57   59   53   56   78   57  54.2    D-
19991   Lucas       Trever          0   77   90   75   53   88   61   63  64.4    D-
63757   Jones       James          82   67   59   85   80   89   93   87  75.8    D-
78759   Komorowski  Ethan          69   69   79   82   61   63   82   55  68.4    D-
99076   Hebb        Emily          78   68   59   77    0   93   68   54  56.6    D-

                       Average:  67.7 66.9 73.8 77.1 71.0 70.7 73.2 76.5  67.7

Press any key to continue . . .
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;

struct student
{
	int id;
	string fname;
	string lname;
	double gr[8];
	double avg;
	string letGr;
};

void print(student arr[], int cnt)
{
	cout << endl;
	cout << "Total Number of Students: " << cnt;
	cout << endl;
	cout << " ID      LName      FName          Q1   Q2   Q3   MT   Q4   Q5   Q6    F   Avg  Grade" << endl;
	cout << "-------------------------------------------------------------------------------------" << endl;
	for (int i=0;i<cnt;i++)
	{
		cout << setprecision(0);
		cout << setw(2) << arr[i].id << "   " << left << setw(12) << arr[i].fname 
			 << setw(12) << arr[i].lname << right;
		for (int j=0;j < 8;j++)
			cout << setw(5) << arr[i].gr[j];
		cout << setprecision(1);
		cout << "  " << arr[i].avg  << "    " << arr[i].letGr << endl;
	}
	cout << endl;
}
double studAvg(student rec)
{
	int s=0;
	int m=0;
	int f=0;

	for (int i=0; i < 8; i++)
		s += rec.gr[i];
	m = rec.gr[3];
	f = rec.gr[7];

	if (rec.gr[0] <= rec.gr[1] && rec.gr[0] <= rec.gr[2] && rec.gr[0] <= rec.gr[3] && rec.gr[0] <= rec.gr[4] && rec.gr[0] 
		<= rec.gr[5] && rec.gr[0] <= rec.gr[6] && rec.gr[0] <= rec.gr[7])
		return (((s - rec.gr[0]) + m + (2 * f)) / 11.0);
	else if (rec.gr[1] <= rec.gr[0] && rec.gr[1] <= rec.gr[2] && rec.gr[1] <= rec.gr[3] && rec.gr[1] <= rec.gr[4] && rec.gr[1] 
		<= rec.gr[5] && rec.gr[1] <= rec.gr[6] && rec.gr[1] <= rec.gr[7])
		return (((s - rec.gr[0]) + m + (2 * f)) / 11.0);
	else if (rec.gr[2] <= rec.gr[0] && rec.gr[2] <= rec.gr[1] && rec.gr[2] <= rec.gr[3] && rec.gr[2] <= rec.gr[4] && rec.gr[2] 
		<= rec.gr[5] && rec.gr[2] <= rec.gr[6] && rec.gr[2] <= rec.gr[7])
		return (((s - rec.gr[1]) + m + (2 * f)) / 11.0);
	else if (rec.gr[4] <= rec.gr[0] && rec.gr[4] <= rec.gr[2] && rec.gr[4] <= rec.gr[1] && rec.gr[4] <= rec.gr[4] && rec.gr[4] 
		<= rec.gr[5] && rec.gr[4] <= rec.gr[6] && rec.gr[4] <= rec.gr[7])
		return (((s - rec.gr[2]) + m + (2 * f)) / 11.0);
	else if (rec.gr[5] <= rec.gr[0] && rec.gr[5] <= rec.gr[1] && rec.gr[5] <= rec.gr[2] && rec.gr[5] <= rec.gr[3] && rec.gr[5] 
		<= rec.gr[4] && rec.gr[5] <= rec.gr[6] && rec.gr[5] <= rec.gr[7])
		return (((s - rec.gr[3]) + m + (2 * f)) / 11.0);
	else if (rec.gr[6] <= rec.gr[0] && rec.gr[6] <= rec.gr[1] && rec.gr[6] <= rec.gr[2] && rec.gr[6] <= rec.gr[3] && rec.gr[6] 
		<= rec.gr[4] && rec.gr[6] <= rec.gr[6] && rec.gr[6] <= rec.gr[7])
		return (((s - rec.gr[4]) + m + (2 * f)) / 11.0);
	else
		return ((s + m + (2 * f)) / 11.0);
}


double average(student arr[], int cnt, int i)
{
	double s=0;
		
	for (int j=0; j < cnt; j++)
		if (i > 0)
			s += arr[j].gr[i];
		else
			s += arr[j].avg;
	
	return s/cnt;
}

string letterGrade(double studAvg)
{
	if (studAvg > 95.0) return "A";
	else if (studAvg > 90.0) return "A-";
	else if (studAvg > 85.0) return "B";
	else if (studAvg > 80.0) return "B-";
	else if (studAvg > 75.0) return "C";
	else if (studAvg > 70.0) return "C-";
	else if (studAvg > 65.0) return "D";
	else if (studAvg > 60.0) return "D-";
	else return "F";
}

void sort(student arr[], int c)
{
	student t;

	for (int i=c-1; i < 1; i--)
		for (int j=1; j < i; j++)
			if (arr[j+1].fname < arr[j].fname)
			{
				t = arr[j]; arr[j] = arr[j+1]; arr[j+1] = t;
			}
}


void main()
{
	ifstream inF;
	student myStuds[73];
	int cnt=0;
	int i;
	double classAvg;
	string fname, lname, id;

	cout << fixed << setprecision(1);

	inF.open("students.txt");


	inF >> myStuds[cnt].id;
	while (!inF.eof())
	{
		inF >> myStuds[cnt].fname;
		inF >> myStuds[cnt].lname;
		for (i = 0; i < 8; i++)
			inF >> myStuds[cnt].gr[i];
		myStuds[cnt].avg = studAvg(myStuds[cnt]);
		myStuds[cnt].letGr = letterGrade(myStuds[i].avg);

		cnt++;
		inF >> myStuds[cnt].id;
	}
	inF.close();
	classAvg = average(myStuds, cnt, i);
	print(myStuds, cnt);
	cout << "                       Average: ";
	for (int i=0; i < 8; i++)
		cout << setw(5) << average(myStuds, cnt, i);
	cout << setw(6) << classAvg <<  endl << endl;
}

Try this

instead of

string letterGrade(double studAvg)
{
	if (studAvg > 95.0) return "A";
	else if (studAvg > 90.0) return "A-";
	else if (studAvg > 85.0) return "B";
	else if (studAvg > 80.0) return "B-";
	else if (studAvg > 75.0) return "C";
	else if (studAvg > 70.0) return "C-";
	else if (studAvg > 65.0) return "D";
	else if (studAvg > 60.0) return "D-";
	else return "F";
}

try

string letterGrade(double studAvg)
{
	if (studAvg > 95.0) return "A";
	else if (studAvg > 90.0 && studAvg <= 95) return "A-";
	else if (studAvg > 85.0 && studAvg <= 90) return "B"; // etc
}

EDIT: Sorry, I jumped the gun, what exactly is the error?

Try this

instead of

string letterGrade(double studAvg)
{
	if (studAvg > 95.0) return "A";
	else if (studAvg > 90.0) return "A-";
	else if (studAvg > 85.0) return "B";
	else if (studAvg > 80.0) return "B-";
	else if (studAvg > 75.0) return "C";
	else if (studAvg > 70.0) return "C-";
	else if (studAvg > 65.0) return "D";
	else if (studAvg > 60.0) return "D-";
	else return "F";
}

try

string letterGrade(double studAvg)
{
	if (studAvg > 95.0) return "A";
	else if (studAvg > 90.0 && studAvg <= 95) return "A-";
	else if (studAvg > 85.0 && studAvg <= 90) return "B"; // etc
}

ok.....tried it

string letterGrade(double studAvg)
{
	if (studAvg > 95.0) return "A";
	else if (studAvg > 90.0  && studAvg <= 95.0) return "A-";
	else if (studAvg > 85.0  && studAvg <= 90.0) return "B";
	else if (studAvg > 80.0  && studAvg <= 85.0) return "B-";
	else if (studAvg > 75.0  && studAvg <= 80.0) return "C";
	else if (studAvg > 70.0  && studAvg <= 75.0) return "C-";
	else if (studAvg > 65.0  && studAvg <= 70.0) return "D";
	else if (studAvg > 60.0  && studAvg <= 65.0) return "D-";
	else return "F";
}

but, it still doesn't want to work....

what's the error msg or undesirable result that you're getting?

what's the error msg or undesirable result that you're getting?

using the above function, I am getting the following output:

Total Number of Students: 73
 ID      LName      FName          Q1   Q2   Q3   MT   Q4   Q5   Q6    F   Avg  Grade
-------------------------------------------------------------------------------------
45256   Rodrigues   Joana          58   75   58   61   59   75   63   92  66.2    F
37915   Wright      Michelle       98   83   56   62   63   90   57   67  62.6    F
81984   Williams    Jenny          55   67   54   63   89   84   93   75  66.0    F
73984   Phaneuf     Lesley         78   85   57   51   68   94   51   83  65.1    F
80886   Laflamme    Nicole         76   51   71   94   69   78   87   91  74.3    F
39473   Kenyon      Patricia       65   54   90   68   94   70   95   97  75.5    F
12127   McCabe      Kelly          51   96    0   64   54   75   71   94  60.1    F
52458   Whitten     Sarah          99   58   94   82   81   75   82   70  69.5    F
77921   Connors     Sarah          52   58   88   63   61   65   78   78  64.5    D-
28810   Navin       Joshua         94   75   62   93   64   92   87   94  78.8    D-
31571   Toporowski  Crystal        93    0   77   77   63   68   88   58  56.7    D-
33580   Ziolko      John           74   64   98   92   98   89    0   79  67.8    D-
14508   Stronach    Kurt           80   95   96   84   78   86   53   59  68.6    D-
44520   Ecklord     Ryan            0   61   56   86   98   98   59   83  72.1    D-
15246   Berling     Danielle       85   64    0   75   69    0   54   85  55.7    D-
16137   Littlefield Arionna        71   85   74   97   69   64   82   95  75.2    D-
62631   Niedojadlo  Evan           73   66   83   97   97   51   66   88  72.5    D-
59640   Knieriem    Brandon        52   87   97   66   97   90   93   56  69.5    D-
44102   Spence      Arthur         85   84  100   82   91    0   95   62  65.7    D-
42331   Rose        Nicole         83   50   96   68   54   62    0   93  64.2    D-
72054   Houde       Jessica        72   66   71   62   75   71   86  100  78.6    D-
24609   Cooper      Camille        62   93   92   72   58   76   57   66  65.6    D-
85736   Hepburn     Spencer        71    0   62   60   52   62   64   51  46.6    D-
87129   Morang      Nicholas       77   67   57   89   88   64   68   78  69.6    D-
43865   Hildebrandt Stephenson     97   94   93   93   82   88   78  100  85.1    D-
78575   Suslovic    Vikilynn       65   54   74   67   61   76   69   76  63.3    D-
58751   Flores      Jose           58   80    0   74   87   95   96   69  62.8    D-
18140   Galotti     Salvator       78   65   90   66   88   57   93   98  75.5    D-
10364   Denaro      Tony           73   85   55   72   68   91   55   89  68.5    D-
99189   Vasquez     Oskar          66   60    0   75   63   92   92   52  56.3    D-
21705   Roy         Jake           86    0   89   94   82    0   60   98  64.8    D-
50838   Burr        Jermiah        83   84   94   90   77   73   72   63  77.5    D-
32998   Benway      Eileen         76   98   80   69   75   94   77   95  76.6    D-
87361   Perlmutter  Diadre         96   60   81   88   81   53   91   74  70.2    D-
61084   Cruz        Waldemar       70   68   76   87  100   80   92   86  77.1    D-
54378   Franco-BanksNixaliz        99   58   80   66   63   59   98   83  67.2    D-
10984   Juste       Kerlande       97   73   98   86   96   73   68   57  77.1    D-
77463   Weber       Jessica        60   56   77   62   81   74   78   69  63.4    D-
36278   Hartman     Kristine      100   62   71  100   69   51   58   55  61.5    D-
94304   Bowdy       James           0   57   70  100   92   84   50   98  77.0    D-
55937   Kantzios    Angela         55    0   78   86   93   73   82   76  66.0    D-
17600   DeNinno     David          62   68   93   88   84   60   98   75  70.7    D-
28248   Courville   David          81   88   89   52   64   79   89   87  69.6    D-
61316   Eaton       John           80   51   93   67   90   92   76   69  67.5    D-
84511   Calluari    Henry          72   84   97   59   73    0   86   74  63.0    D-
39234   Spaulding   Nicholas       61    0   76   90   92   53   75   54  58.0    D-
33068   King        Nicholas       70   83   83   89   51   98   75   70  69.5    D-
45403   Breault     Matthew        52   75   70   64   91   59   57   94  69.3    D-
29303   Morales     Lynaska        65   56   97   65   98   73   99   76  71.0    D-
28432   Calle       Juan          100   51   51   65   69   59   68   90  63.5    D-
85434   Hagen       Amanda         72   90   99   71   87    0   81   98  72.2    D-
79998   Szostak     Patrycja       58   67   56   68   77   96    0   81  59.6    D-
19374   Gurung      Manoj          98   85   92   93   85   95   93   99  84.8    D-
46103   Shaw        Lindsay        97   85   85   89   64   57   89   73  71.4    D-
13009   Palko       Michael        98   82   92   51    0   80   73   88  63.5    D-
55698   Reyes       Joselina       59   81   53   90   80   94   79   93  74.9    D-
64779   Alba        Sasha          55   67   93   64    0   91   92   55  54.4    D-
86071   Aimetti     Sean           51   83   88   98   91   83   75   66  74.0    D-
33205   Roberts     Thomas         86   94   70   88   64   88   64   87  75.7    D-
81233   Procko      Nancy          69   51   57   80   52   66   61   51  54.5    D-
90219   June        Christopher    66   86   80   60   71    0   76   80  61.7    D-
39285   Calluari    Joel           77   57   71   78   58   94   71   75  66.5    D-
44686   Soulliere   Jane           69   55   80   95   67   76   89   62  67.5    D-
51785   Kokoszka    Elizabeth      71   61   77   83    0   96   84   56  58.7    D-
26789   Irizarry    Elsie          87   77   76   68   65  100   95   79  72.5    D-
11371   Berry       Angela         90   77   54   76   90   64   97   77  70.7    D-
92521   Cyr         Gregory        59   86   97   85   59   62    0   72  62.7    D-
90742   Manfredi    Kathryn        94   65   81   90   67   66   79   52  71.6    D-
71831   Oquendo     Jessica        60   60   57   59   53   56   78   57  54.2    D-
19991   Lucas       Trever          0   77   90   75   53   88   61   63  64.4    D-
63757   Jones       James          82   67   59   85   80   89   93   87  75.8    D-
78759   Komorowski  Ethan          69   69   79   82   61   63   82   55  68.4    D-
99076   Hebb        Emily          78   68   59   77    0   93   68   54  56.6    D-

                       Average:  67.7 66.9 73.8 77.1 71.0 70.7 73.2 76.5  67.7
            Standard Deviation:   7.4 22.5 23.0 13.3 22.2 25.3 22.3 15.0   7.4
                       Highest:   100   98  100  100  100  100   99  100    85
                        Lowest:    51   50   51   51   51   51   50   51    47
                        Median:    76   74   76   76   76   76   75   76    66
Press any key to continue . . .

but, I looking for the grades to be output based upon a standard grading scale, using the students average:

A = 95 and up
A- = 90 to 95
B= 85 to 90
B- = 80 to 85

etc.....

for example, student #0 (Rodrigues Joana) has a avg of 66.2, so it should be considered a D-.....but it's not coming out like that...

myStuds[cnt].letGr = letterGrade(myStuds.avg); Why are you calling myStuds here and not myStuds[cnt]. Also version with only one comparison is sufficient here.

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.