Averaging test scores

Im writing a program that will ask a user how many tests they have, read those tests, average them, and then display the average as a pass or a fail. IE A is a 80% or higher, using a seperate function to average the imput values. Errors are in the lrt string section. Can anyone see where Im going wrong? Thanks


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <cmath>
#include <cassert>
 #include <cctype>
 #include <conio.h>
using namespace std;

double avg(double ttl, int z); 

//Main function variables
int main()
{
	int numberoftests;
	double totaltestscore = 0.0;

	//Purpose of the program
	cout <<"Today you are finally able to imput all of your tests, " ;
		cout << "and see if you are passing or failing." ;
		cout <<"So How many test are we averaging buddy? " ;

		//Getting the number of tests from the user
		cin >> numberoftests;

		//Looping to collect all the test scores
		for (int i=0; i < numberoftests; i++)
		{
			//indtestscore is the users each individual test score
			double indtestscore, average;
			cout << "Imput your test score bitch.." ;
				cin >> indtestscore;
			//Adding this to the total
			totaltestscore+=indtestscore;
		}


		double average;
		average = avg(totaltestscore, numberoftests);
		string ltr = "";
		cout << "Looks like your average is a" << average << "." ;

		if (average <= 49)
			ltr = "F, you fail... Congrats";
		if (average <= 59 && average >= 50)
			ltr = "D";
		if (average <= 69 && average >= 60)
			ltr = "C";
		if (average <= 79 && average >= 70)
			lrt = "B";
		if (average >= 80)
			lrt = "A... Browner";

		cout <<"Your grade is" << lrt;
}


//The function to calculate the average of the user
	
double avg(double ttl, int z);
{
	double average;
	average = ttl/z;
	return average;

	}
Dear,

You have Declared the string with the name

string ltr = "";

But you wee using the name as lrt in below lines:

if (average <= 79 && average >= 70)
lrt = "B";
if (average >= 80)
lrt = "A... Browner";

cout <<"Your grade is" << lrt;

Thus replace the name of string variable to ltr from lrt.

Like This:

if (average <= 79 && average >= 70)
ltr = "B";
if (average >= 80)
ltr = "A... Browner";

cout <<"Your grade is" <<ltr;

Now Secondly in the defination body of function avg.

double avg(double ttl, int z);
{
double average;
average = ttl/z;
return average;

}

Remove the semi-colon after the function declaration thus the function defination will look like

double avg(double ttl, int z)
{
double average;
average = ttl/z;
return average;

}

Try these changes and let me know if you need more help on this.

Take Care :)
Last edited on
dude..corrected all the errors..try this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <cmath>
#include <cassert>
#include <string>
#include <cctype>
#include <conio.h>
using namespace std;

double avg(double ttl, int z); 

//Main function variables
int main()
{
	int numberoftests=0;
	double totaltestscore = 0.0;
	double indtestscore=0.0,average=0.0;

	//Purpose of the program
	cout <<"Today you are finally able to imput all of your tests, " ;
	cout << "and see if you are passing or failing." ;
	cout <<"So How many test are we averaging buddy? " ;
		//Getting the number of tests from the user
	cin >> numberoftests;

		//Looping to collect all the test scores
	for (int i=0; i < numberoftests; i++)
	{
		//indtestscore is the users each individual test score
		
		cout<<"Imput your test score bitch.." ;//wow u better mind he language u use :P
		cin>>indtestscore;
		//Adding this to the total
		totaltestscore+=indtestscore;
	}


		
		average = avg(totaltestscore, numberoftests);
		std::string ltr=" ";
		cout << "Looks like your average is a" << average << "." ;

		if (average <= 49)
			ltr = "F, you fail... Congrats";
		if (average <= 59 && average >= 50)
			ltr = "D";
		if (average <= 69 && average >= 60)
			ltr = "C";
		if (average <= 79 && average >= 70)
			ltr = "B";
		if (average >= 80)
			ltr = "A... Browner";

		cout <<"Your grade is" << ltr;
}


//The function to calculate the average of the user
	
double avg(double ttl, int z)
{
	double average;
	average = ttl/z;
	return average;

	}
Last edited on
Topic archived. No new replies allowed.