Computer Science Canada Program using nested ifs |
Author: | stef_ios [ Wed Jan 23, 2008 3:56 pm ] | ||
Post subject: | Program using nested ifs | ||
Hey all. So i'm writing a program that asks the user for four marks. a)All the marks are out of 100, and are equally weighted in the average. b)Grades are assigned based on A = 80 ? 100, B = 70 ? 79, C = 60 ? 69, D = 50 ? 59, F = 0 ? 49 c)If the student fails (i.e. mark < 50) either or both assignments, the grade is reduced by 1 (e.g. B becomes C). d)If the student fails either or both tests, the mark will be F. So here is my program. I am having some trouble with part c) and was wondering if anyone could let me know what I need to do for the program to reduce the mark by one. Also, how do I get the program to make sure a number above 100 is not entered for the test or assignment marks.
So that is what I have. So any help would be great! ![]() |
Author: | OneOffDriveByPoster [ Wed Jan 23, 2008 9:26 pm ] | ||
Post subject: | Re: Program using nested ifs | ||
stef_ios @ Wed Jan 23, 2008 3:56 pm wrote:
|
Author: | md [ Thu Jan 24, 2008 1:04 am ] |
Post subject: | RE:Program using nested ifs |
No, the code is not even close to being correct. I sugest looking up "else if" and comparisons to start. And as OneOffDriveByPoster said, try compiling your code and fixing all the errors. |
Author: | stef_ios [ Fri Jan 25, 2008 6:38 pm ] |
Post subject: | RE:Program using nested ifs |
Okay, i'll start with that. Thanks! |
Author: | stef_ios [ Wed Jan 30, 2008 2:06 pm ] | ||
Post subject: | Re: Program using nested ifs | ||
Okay, so thanks to a few great sites and my C books, I have managed to get my program to work. Now the only problem I am running into is that the program is being terminated even when the statement is not true. I got the testing of the test marks to work, and print "You got an F!" if one of the tests is failed. But if the tests were passed, and say the student got a %60 average, it is still printing "You got an A!". Can someone tell me why this is happening? Here is my code:
|
Author: | OneOffDriveByPoster [ Wed Jan 30, 2008 3:33 pm ] | ||||
Post subject: | Re: Program using nested ifs | ||||
|
Author: | stef_ios [ Thu Jan 31, 2008 2:05 pm ] |
Post subject: | RE:Program using nested ifs |
Okay so I put that in, but do I need to put that in for each case? Or just for the 80-100? And what does that bit of code mean? Why average && average, and not just average? Thanks |
Author: | Clayton [ Thu Jan 31, 2008 2:13 pm ] |
Post subject: | RE:Program using nested ifs |
&& is equivalent to and |
Author: | stef_ios [ Fri Feb 01, 2008 5:01 pm ] |
Post subject: | RE:Program using nested ifs |
Oaky, I put it in, but it's still terminating the program even if the condition is false. |
Author: | stef_ios [ Sun Feb 03, 2008 1:10 pm ] |
Post subject: | RE:Program using nested ifs |
Any other suggestions as to why my program is not working, and how I can make it work? |
Author: | md [ Sun Feb 03, 2008 1:39 pm ] |
Post subject: | RE:Program using nested ifs |
Can you post your new code? Then we could point out possible errors in it. It would also be a good idea to cut out everything except the first if for now; get one small part working and them move on to the rest. |
Author: | stef_ios [ Sun Feb 03, 2008 4:06 pm ] | ||
Post subject: | Re: Program using nested ifs | ||
Okay so here is the if statements part of my code, because I know the first part works.
So basically, it has to scan the average, but even if the average is below 80, it is still saying "You got an A". It's not even scanning the other if statements, even if the condition is false. |
Author: | Tony [ Sun Feb 03, 2008 4:13 pm ] | ||||
Post subject: | Re: Program using nested ifs | ||||
Lets try this one again... OneOffDriveByPoster @ Wed Jan 30, 2008 3:33 pm wrote:
or more specifically (80 <= average) && (average <=100) boolean logic is calculated one piece at a time, connected together by and, or, and other boolean statements. |
Author: | stef_ios [ Sun Feb 03, 2008 4:23 pm ] |
Post subject: | Re: Program using nested ifs |
Thanks so much! It works! Okay, so I have one more thing to do for my program. If the student fails (i.e. mark < 50) either or both assignments, the grade is reduced by 1 (e.g. B becomes C). So how do get my program to do this? |
Author: | md [ Mon Feb 04, 2008 12:36 am ] | ||
Post subject: | RE:Program using nested ifs | ||
the way you have your code now you could just add some more if statements like
Clearly that's a basic example; and you'd need to expand upon it |
Author: | stef_ios [ Mon Feb 04, 2008 12:37 pm ] |
Post subject: | RE:Program using nested ifs |
Thanks, i'll work on it!! ![]() |
Author: | stef_ios [ Tue Feb 05, 2008 1:16 pm ] |
Post subject: | RE:Program using nested ifs |
So for that bit of code you posted, md, would I do that for each mark category. And then for the lesser grade put what the grade is below the category "whatever_A_is" and then for the greater grade put "You got an A"? So I would need four extra if statements. |
Author: | md [ Tue Feb 05, 2008 2:36 pm ] |
Post subject: | RE:Program using nested ifs |
Err... I suppose... what I meant was that the lesser grade would be like a C if the higher grade is a B. Mostly I'm just throwing ideas out there though, it's up to you to figure out a solution that you are happy with (and understand). |
Author: | stef_ios [ Tue Feb 05, 2008 3:11 pm ] |
Post subject: | RE:Program using nested ifs |
Gotcha. Thanks. ![]() |