Just a hitch up. I've been doing this already but can't seem to make it run and sorry I haven't replied to my first topic already. Been busy on some other stuff. I might dig it back when I have time. For the meantime, I am creating a C++ program that will accept the final grade and display its equivalent based on the below table
Grade Equivalent
0.0 -> 59.4 0.00 F
59.5 -> 64.4 1.00 D
64.5 -> 70.4 1.50 D+
70.5 -> 76.4 2.00 C
76.5 -> 82.4 2.50 C+
82.5 -> 88.4 3.00 B
88.5 -> 94.4 3.50 B+
94.5 -> 100.0 4.00 A
In this code there are many problems: the if one after the other don't make a lot of sense. Also the variables char A, B, .... Those should not be variables, but the values of your table.
vector<pair<double, string> >::iterator it = table.begin();
it += segment;
num_grade = it->first;
letter_grade = it->second;
cout << "Your grade is " << num_grade << " and your letter grade is " << letter_grade << endl;
Welcome to cplusplus :+D and seasons greetings while we are at it !!
First up, about how to post a question. So actually ask a question to start with. Specify what your problem is, and where you think it might be going wrong. If your code doesn't compile (yours doesn't), post the compiler errors in full and make sure the line numbers in the errors match the code you posted.
OK, just some stuff to realise about your code.
With nested if statements, the inner part only executes if the outer part is true. For example, line 24 executes only if line 22 is true and so on. So the code doesn't do what you want. Investigate the use of an elseif statement.
Also, when an if statement evaluates to false, execution continues after the compound statement that follows the the if statement ( that is, what is executed if true part). So if line 22 evaluates to false, then execution jumps to line 42. With that, you don't have your closing braces - these must match up. One can set their IDE to do this automatically. The lack of braces should have generated lots of compiler errors.
Now for the biggest problem often encountered by beginners: initialisation of variables. What is the value of letgrade on line 36? Or at any stage for that matter? Always initialise your variables to something, preferably at declaration. For letgrade , I would have initialised it to 'Z' , that way if you see that in the output, you might realise that you haven't set it anywhere.
With the variables B,B+, just wondering what you are going to store in those. Do you realise that a char only holds a single character? Could your get away without those variables?
There we go, some stuff to work on :+) Hope it all helps a bit.
I don't think the OP is at the stage of the course that they have been taught about vectors pairs or iterators - so simple if statements is probably all they are after. But be careful not to do the homework for them.
Any way, regards & seasons greeting to you as well :+D Cheers
Edit:
@JemCel03
Also, this post belongs in the beginners section, you can edit your post and move it there.