A quick question about if/else

I need help with the following problem. I normally would just type a conditional expression like it states below; but, since I can't format my statement that way I don't understand how else I could do it.

Write a program that will let the user enter a grade, and the program will output what number they should expect with that grade. e.g. If I were to enter C-, the computer will tell me “1.7”. Use the following list as a grading scale. Assume that the user will only enter string ranging from B- to A+. You must use nested statements and the input must be a single string, not two CHAR nor two strings.

You can NOT use (if string_from_user == “A+”). (Syntactically you can, but for this problem you cannot.)


I could go ahead and code it using the conditional expression above but I am not allowed to use it so if I could just get advice on what to do I'd greatly appreciate it.
Maybe this would be allowed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if (string_from_user[0] == 'A')
{
   if (string_from_user[1] == '+')
   {
     // grade = ...
   }
  else if (string_from_user[1] == '-') 
   {
     // grade = ...
   }
}
else if (string_from_user[0] == 'B') 
{
   if (string_from_user[1] == '+')
   {
    // grade = ...
   }
  else if (string_from_user[1] == '-') 
  {
    // grade = ...
  }
}
I believe that it would. I just learned about if/else statements and did not know that you can have an if/else if statement inside of an if statement. I feel like I can go attempt it now haha. Thanks :]
Actually I just started it and ran into another question, sorry haha.
what does the bracket with a 0 or 1 designate?
what does the bracket with a 0 or 1 designate?

That's a subscript. It refers to the n'th character of the string.
http://www.cplusplus.com/reference/string/string/operator[]/
"nested statements" means having statements inside of statements
Topic archived. No new replies allowed.