On lines 13-15 you
declare your variables.
On lines 21, 23, 25, 27 you send junk values as arguments because no where did you
assign values to these variables, which is what initialisation is. The code in the getMarks function only works because the junk value (somewhere in between +/- 2 billion) is likely not between 0 & 100. So you can see this is bad practice
Try declaring & initialising your variables at the same time, 1 per line. Sometimes, zero is not a good choice, but seems to be OK here :
1 2 3 4 5
|
int MidtermMark1 = 0; // between 0 & 100, 30% of Overall - the first test
int MidtermMark2 = 0; // between 0 & 100, 30% of Overall - the second test
int FinalMark = 0; // between 0 & 100, 40% of Overall - the last assignment
int OverallPercent = 0; // Percentage in course
char letterGrade = 'Z'; // can be A, B, C, D or F
|
You can see I have used better variable names to make the code self documenting. They are initialised, and I have used comments to give important info about valid ranges, and what the variable is used for.
If you work in the IT industry, this stuff is important - the tired old grumpy maintenance programmer looking at your code will immediately see what is going on. It can also be useful when looking at your own code 2 or 3 years later.
The variable OverallPercent should be a double, because it gets promoted to this type on line 62, and returning it on line 63 should attract a warning (loss of precision double to int). You can use
static_cast<int>
to cast it to an int before returning it. Have a look at the reference material top left of this page.
Be careful naming local variables inside a function the same as those in main() - I know you have done it to reinforce the idea that they are the same thing, but now they have different types.
Hope all goes well.