trouble! help?

i need help im trying to get the second line to output but it just keeps saying the same thing as if i put in a and says excellent work, how do i get it to say above average work and output it as so? i have everything set right

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
  Put the code you#include <iostream>

using namespace std;

int main()
{
	
	int grade = 'a'; 
	char b;
	b = 'b';
	
	
	cout << "enter the last grade you got on your exam" << endl;
	cin >> grade;
	if (grade = 'a')
	{
		cout << "Excellent work!" << endl;
	}
	else if (grade = 'b')
	{
		cout << "above average work" << endl;
		
	}





}



	




Hi tyler,

= is the assignment operator. It's used to assign a value to a variable.
== is the equality operator. It's used to test whether two values are equal.

Change line 15 to be if (grade == 'a')
Change line 19 to be if (grade == 'b')

Also, lines 9 and 10 are pointless, you should remove them.

Hope that helps.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
using namespace std;
int main()
{
    char grade ;
    cout<<"\nEnter The Grade of The Student (A/B) " ;
    cin>>grade ;
    if (grade == 'A' || grade == 'a')
      cout<<"\nExcellent Work\n";
    else
       if (grade == 'B' || grade =='b')
        cout<<"\nAbove Average Work...\n";
    else
         cout<<"\nINVALID INPUT!!!";
    return 0 ;
}


Here you need to change code with (grade==a) as well as (grade==b), This is the right step to follow for getting a suitable result.

cout << "enter the last grade you got on your exam" << endl;
cin >> grade;
if (grade = 'a')
{
cout << "Excellent work!" << endl;
}
else if (grade = 'b')
{
cout << "above average work" << endl;


For more visit:- http://www.traininginlucknow.in/best-c-language-training-in-Lucknow.html
Topic archived. No new replies allowed.