# help with nested ifs

• 02-15-2012
marlin
help with nested ifs
Hey this is my homework assignment. I'm stuck on part c; which asks me to reduce the grade by 1 letter if assignement 1 or 2 is failed. I'm not sure how to do this because i can only express it if the value was to be presented as an integer; rather then a letter grade. Here is what i have so far:

Code:

```#include<stdio.h> #include<conio.h> int main () { int test1,test2,ass1,ass2; float av1,av2; printf("Please enter your first four marks\n"); scanf("%d%d%d%d",&test1,&test2,&ass1,&ass2); av1=(test1+test2+ass1+ass2)/4; av2=av1-10; printf("Your average is %f\n", av1); if(test1<50 && test2<50){ printf("The letter is F"); } if(av1<50){ printf("The letter is F"); } else if(ass1<50){ printf("The number %f is reduced by one grade",av1); } else if(ass2<50){ printf("The number %f is reduced by one grade",av1); } else if(av1>50 && av1<59){ printf("Your mark is D"); } else if(av1>60 && av1<69){ printf("Your mark is C"); } else if(av1>70 && av1<79){ printf("Your mark is B"); } else if(av1>80 && av1<100){ printf("Your mark is A"); } else { printf("The number is invalid"); } getch(); }```

the assignment:
1. Write the algorithm (pseudocode) for the following program definition: Read in a set of 4 marks for a student, representing two test marks followed by two assignment marks. Calculate and print a final grade, using the following information:
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 – 49c)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.
*you must use nested ifs*
• 02-15-2012
quzah
They wanted you to write pseudocode, not actual code. They wanted you to work out the logic on paper (or on your PC, whatever) on how to do it before attempting to do it.

Lets say I have four ingredients, and I am supposed to make them into a sandwich. A sandwich is: one bread on the bottom, ingredients in the middle, one bread on top. No two ingredients will be next to one another. The ingredients come in random order.

How do you make a sandwich?
Code:

```for every ingredient     if we have no bottom bread and this is not a piece of bread         ignore ingredient     else     if we have a bottom bread and this is a bread         if the last ingredient was not a bread             done with sandwich         else             bread on bread, not a valid sandwich, ignore this item     else         /* some non-bread ingredient, and we have a bottom bread so... */         if last ingredient is this ingredient             ignore this ingredient because it's same on same         else             put this on the sandwich```

Quzah.
• 02-15-2012
marlin
Ok thanks for the example. I'm still not sure about part c however. Part 2 of the assignment is to run the program using quincy and remove all errors, which i have done. I still don't understand how to display one grade below the one that has actually been calculated by the program!
• 02-15-2012
You know of course, that A is right next to B, in the alphabet - naturally.

What you may not have explored is that in the character set for your computer A is also right next to B. Typically A is 65 inside the computer, and B is 66. C is 67, etc.

So to lower a grade, by one grade, you need to add one to the grade they have now, if that grade is A thru D. Don't lower an F grade, however. A+1 equals B!
• 02-15-2012
laserlight
Quote: