IF statements using only single character

Here is the scenario:
Write a c++ program that gets a letter grade from the user. It will be a single character.

If the letter grade entered is a capital A or a capital B or a capital C, the program should print the message: A grade letter of ___ is satisfactory.

If the letter grade entered is a capital D, the program should print the message: A grade letter of D is borderline.

If the letter grade entered is a capital F, the program should print the message: A grade letter of F is failing.

If the user enters anything else, it should print the message :
Invalid letter grade.

Here is what I did, I just want to know if I am on the right track. Please let me know what I did wrong and what I need to do because I am confused as to how to set this up:


int main ()
{// Declarations
char letter= 'A','B', 'C','D','E','F';
char ch='A';
int num=4;
cout << "Enter a single character:";
cin>>letter;
cout<< "A grade letter of __ is satisfactory" << endl;
cin>> A,B,C;
cout<< "A grade letter of D is borderline" < <endl;
cin >> D;
cout << "A grade letter of F is failing" << endl;
cin >> F;
cout << "invalid letter grade" << endl;
cin >> E, num;
cout<< endl;




if (ch='A','B','C')

{
cout << "A grade letter of ___ is satisfactory" << endl;

}
else (ch='E') && (num=4)
{
cout << "Invalid letter grade" << endl;
}
if (ch='D')
{
cout << "A grade letter of D is borderline" << endl;
}

if (ch='F')
{
cout << "A grade letter of F is failing" << endl;
}
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
int main ()
{// Declarations
char letter= 'A','B', 'C','D','E','F';
char ch='A';
int num=4;
cout << "Enter a single character:";
cin>>letter;
cout<< "A grade letter of __ is satisfactory" << endl;
cin>> A,B,C;
cout<< "A grade letter of D is borderline" < <endl;
cin >> D;
cout << "A grade letter of F is failing" << endl;
cin >> F;
cout << "invalid letter grade" << endl;
cin >> E, num;
cout<< endl;




if (ch='A','B','C')

{
cout << "A grade letter of ___ is satisfactory" << endl;

}
else (ch='E') && (num=4)
{
cout << "Invalid letter grade" << endl;
}
if (ch='D')
{
cout << "A grade letter of D is borderline" << endl;
}

if (ch='F')
{
cout << "A grade letter of F is failing" << endl;
}


Line 3: You cannot do this. Basically, right here you're trying to define 7 values to 1 variable which will just cause a ton of errors.

Line 4: You declare this ch, and set it equal to 'A', then later try to do comparisons like the value has changed, even though it hasn't. Also, having two different char variables is superfluous, so I would suggest removing one.

Line 5: I don't know why you have an integer at all, it just seems useless.

Lines 8-16: Get rid of all this.

Line 21: You have the right idea here, but that's not have comparisons work in C++. I think you want "if ch is equal to a or b or c", which would be written,
if (ch =='A' || ch == 'B' || ch == 'C')
Notice that when doing equals comparisons, you use == instead of =. Also, || is the or operator, and each comparison must be separated.

Line 24: Instead of ___ use << ch <<. Close the string on either side.

Line 27: else cannot be followed by conditions. If you wanted conditions, use else if.
Also, move this to the very end.

Make sure you close main with a }.
ok so is this the correct way to type out this code?
#include <iostream>
using namespace std;

int main ()
{
cout << "Rebecca Carolina Katz" << endl;
cout << "Lab 5 part b" << endl;

// Declarations
char ch='A';
cout << "Enter a single character:";
cin>> char;

if (ch=='A' || ch=='B' || ch='C')

{
cout << "A grade letter of << ch << is satisfactory" << endl;

}

if (ch=='D')
{
cout << "A grade letter of D is borderline" << endl;
}

if (ch=='F')
{
cout << "A grade letter of F is failing" << endl;
}

else if (ch=='e' || num=4)
{
cout << " Invalid letter grade" << endl;
}

return 0;


}
I had to include my name and lab number by the way
Topic archived. No new replies allowed.