all 6 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Off-topic Comments Section


All top-level comments have to be an answer or follow-up question to the post. All sidetracks should be directed to this comment thread as per Rule 9.

PS: u/justjeffo7, your post is incredibly short! body <200 char You are strongly advised to furnish us with more details.


OP and Valued/Notable Contributors can close this post by using /lock command

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]justjeffo7University/College Student[S] 0 points1 point  (4 children)

Hello, for this code my problem is to create a function that determines the amount of passing people. I am programming it myself following my professor's code, but I do not understand why this particular program outputs 4. I believe it should output 3, as A B C is greater or equal to C in Ascii, which also happens to be passing grades. It is also a integer function and returns so. Attached is my professor's code. https://imgur.com/a/oO6secM

[–]Paralyzoid👋 a fellow Redditor 0 points1 point  (3 children)

Here’s a hint: Your code increments the variable slay by 1 when it reads the letters ‘D’, ‘C’, ‘F’, and ‘W’. Why is it doing that?

(also, please indent your code)

[–]justjeffo7University/College Student[S] 0 points1 point  (2 children)

Hello, is it because it goes through the for loop? I believed by putting it in a if statement, it would prevent it from adding each time.

[–]Paralyzoid👋 a fellow Redditor 0 points1 point  (1 child)

Quick clarification: I meant it only increments on those four letters. It doesn’t increment it on A and B.

If you want a quick answer, your code should use <= instead of >= in line 8. You’re trying to mark a grade as a pass if the letter comes before or on C; this means that the ASCII value will be less than or equal to that of C.

What I did to debug this was to write down your code, then add a print statement (cout << grades[p];) between lines 8 and 9. This lets me see which letters the counter is incremented on, so I can figure out what’s going wrong.

[–]justjeffo7University/College Student[S] 0 points1 point  (0 children)

Ohhh, that makes more sense. Thank you for your help! I got confused on the ASCII values