Using String to output a grade

I have a program where you imput a grade from 0% to 100% and it will output your letter grade. Im getting an error saying cout is ambiguous. Any help would be appreciated!
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
#include <iostream>
#include <cmath>
#include <cassert>
 #include <cctype>
 #include <conio.h>
#include <string>
using namespace std;


//Main function variables
int main()
{
	
	double average;

	//Purpose of the program
	
	cout <<"\nPlease Imput your test score " ;

		//Getting the number of tests from the user
		cin >> 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 << "\nYour letter grade is... " <<ltr;
		getch();
}






There's a big piece of your code missing.
What am I missing?
See this bit:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
	
	double average;

	//Purpose of the program
	
	cout <<"\nPlease Imput your test score " ;

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

		
		}


That's your complete main function. See this bit straight after it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
		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 << "\nYour letter grade is... " <<ltr;
		getch();
}


That's not in any function and it's got a closing } at the end, but there's no opening { that seems to go with it.
There's no definition of ltr
Last edited on
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
#include <iostream>
#include <cmath>
#include <cassert>
 #include <cctype>
 #include <conio.h>
#include <string>
using namespace std;


//Main function variables
int main()
{
	
	double average;

	//Purpose of the program
	
	cout <<"\nPlease Imput your test score " ;

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

		
		{



		
	{
		cout << "bitch" ;
		
		double average;
		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 << "\nYour letter grade is... " <<ltr;
		getch();

	
}

		}



Still not running but I have no errors as I write the program, saying there's an error on #include <iostream>
You have three { but only two }

Why declare average twice?

What are you using the following for?

1
2
3
 #include <cmath>
#include <cassert>
 #include <cctype> 
Last edited on
Got it, thanks!
Topic archived. No new replies allowed.