I've been getting back into C++ but instead of re-learning the material, I decided to look up exercises and see where I stand. Apparently, I'm sitting.
The exercise was to write a program using a switch that will take a numeric score and return a letter grade. When I enter the score, it skips straight to "Press any key to continue..."
Please don't fix my errors; I'd like to fix my own mistakes. I'm just not sure if the problem is in the way I wrote the switch statement or the voids (or both >_<). It may also be my if statements but, I'm inclined to say that I've done those correctly. Here's the code.
Try describing the program (not to me, in your head or out loud to yourself), line by line, function by function. Compare that to what you want to happen, then you should find the errors (that's similar to how compilers work idn't it? the 'd' was intentional).
To get you started, the problem is your switch statement. It isn't doing what you think it is. It only accepts two values, 1 and 2, one takes it to the pass () function, which doesn't have anything in the if else statement for anything under 60.
Your if else statement is another thing. if (condition one, condition two) is wrong, don't use a comma to separate conditions. It should be || (or), && (and) and ! (not) (though I am not sure if it can be used in such a sense). So:
if (a == A && A == a)
would be "if 'a' is equal to 'A' and 'A' is equal to 'a'"
listen buddy i guess the variable inside switch brackets can never have the value 1 ... And then call the function pass ... just think.... there must be an if-else statement specifying whether the student is pass or fail and then call the functions....pass or fail
Thanks all for the help! Hopefully as i work on these types of exercises, I'll start to put my knowledge back in order!
@Danny Toledo: Sorry about that! I totally didn't even think about the code brackets! And for correcting my conditionals, I knew the comma was wrong but I didn't even think to look it up! >_<
edit: Am I getting closer by assuming the issue is the relationship between the integer "score" and the cases?
switch(val) {
case 1:
a();
break;
case 2:
b();
break;
case 3:
c();
break;
...
default:
z();
}
//is the same as
if( val == 1 )
a();
elseif( val == 2 )
b();
elseif( val == 3 )
c();
...
else
z();