So ive been working on this for a couple of hours and i hit a couple speed bumps but nothing major. when i got to the " string calculateLetterGrade" i thought i was doing it right following what looked like simple instructions but when i go to call it like i did with the previous function it doesn't work and i cant seem to figure out why.
hey. Looking at it now.
in the meantime, just edit your post, highlight the code, and use the <> symbols in the box next to the editor to make it more codeish.
first thing is do a search and replace of float with double. Floats are nothing but trouble.
second, if it is an integer, use integers. grade seems like it should be type int or unsigned int.
strings use " not '
so you need to return
"A+" not 'A+'
this may be the issue. still looking though.
you assign grade a string. you should have a string variable instead, grade is a float...
string calc(int grade)
string result = "";
if(grade < 50)
result = "F"; //like this
... more if statements
also, going backwards makes it easier on the eyes. IF you just return the value this way you don't need result to hold the value until the end. logically that is:
if < 50
if(< 53) //to get here, it has to be 50 or more
return "D-"; //to get here it has to be less than 53... see how they chain?
I was trying that, not sure why its not working. Im selecting all the code part of the post and clicking the <> icon but nothing seems to happen and when i submit it still looks the same. gonna try on a different browser maybe.
yeah another thing the calculateAverage has to be a float with 5 parameters of type float and the calculateLetterGrade has to be a string with one parameter of type float called grade. should have clarified beforehand.
Ill try the " instead of '
well the other week he had us make a average, min, max, sum calculator with only if statements. to teach us that they suck. next week were learning arrays so im looking forward to doing this even faster.
I was still editing above.
I think if you return an actual string from your function it will work now.
The other things I said are just prettys.
if you must use a float, then do what the professor said. Professors these days... they seem to all tell you "write this, but you can't use anything at all and you have to work around these goofy criteria". I guess its kinda like work, actually.
- what thing do I need in order to work out a letter grade? What type of variable is this? This will be your input.
- what thing do I output as a result?
Your function definition currently starts: string calculateLetterGrade(string grade)
Given that the input will be passed to the function as a parameter (in brackets after the function name) does this currently correspond to what you have decided your "input" is?
Now go through your function line by line and ask yourself: am I using a variable whose value I currently know?
(Unless you have some extremely able students you might also like to fix the typo on line 45. You are also suspiciously inconsistent with the < and <=.)
Yeah just noticed your reply. Im new to programming and we were taught to use <= and type the code the way i had written it the first time and so when i was writing it backwards ( that's what it is in my head) which really is the right way i was adding "=" which wasn't needed.
still learning but i had a lot of fun writing this.
Got upset that i couldn't find the mistake which was causing an error on debug but someone helped me find it which in the end was a variable that was initialized to 0 which it wasnt supposed to.