
-----------------------------------
stef_ios
Wed Jan 23, 2008 3:56 pm

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. 



#include 
#include 

int
main(void)

{

	double test1, test2, assignment1, assignment2;

	printf("Please enter the first test mark: ");      
	scanf("%f", &test1);
	printf("You entered: %f \n", test1);"

	printf("Please enter the second test mark: ");      
	scanf("%f", &test2);
	printf("You entered: %f \n",test2);

	printf("Please enter the first assignment mark: ");      
	scanf("%f", &assignment1);
	printf("You entered: %f \n", assignment1);

	printf("Please enter the second assignment mark: ");      
	scanf("%f", &assignment2);
	printf("You entered: %f \n", assignment2);

/* Now using nested ifs the program will use the calculate the average of the entered numbers and will
   determine what the final mark is for the student */
	
	if ((test1+test2+assignment1+assignment2)/4 == '100>80')
      printf ("You got an A! \n");
    
	else
      if ((test1+test2+assignment1+assignment2)/4 == '79>70') 
          printf ("You got a B! \n");
      
	  else
          if ((test1+test2+assignment1+assignment2)/4 == '69>60') 
             printf ("You got a C! \n");
		
		else
          if ((test1+test2+assignment1+assignment2)/4 == '59>50') 
             printf ("You got a D! \n");
			
			else
          	  if ((test1+test2+assignment1+assignment2)/4 == '49>0') 
             	printf ("You got an F! \n");

				else
      		      if (test1,test2 == '50>0') 
          			printf ("You got an F! \n");
					
					else
      				  if ((assignment1, assignment2) == '50>0') 
                    	printf ("You got a  ! \n");
          			
					else
             		  printf ("INVALID MARK! \n");
 
   return (0);

}


So that is what I have. So any help would be great!  :D  Thanks.

-----------------------------------
OneOffDriveByPoster
Wed Jan 23, 2008 9:26 pm

Re: Program using nested ifs
-----------------------------------
printf("You entered: %f \n", test1);"      		      
...
if (test1,test2 == '50>0')Please try to compile your code as you go.  You have an unclosed string literal and '50>0' is not a comparison.  Either that or you have intensionally obfuscated code.

-----------------------------------
md
Thu Jan 24, 2008 1:04 am

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.

-----------------------------------
stef_ios
Fri Jan 25, 2008 6:38 pm

RE:Program using nested ifs
-----------------------------------
Okay, i'll start with that. Thanks!

-----------------------------------
stef_ios
Wed Jan 30, 2008 2:06 pm

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: 



#include 

int
main(void)

{

	double test1, test2, assignment1, assignment2;
	double average;

	printf("Please enter the first test mark: ");     
	scanf("%lf", &test1);

	printf("Please enter the second test mark: ");      
	scanf("%lf", &test2);

	printf("Please enter the first assignment mark: ");      
	scanf("%lf", &assignment1);

	printf("Please enter the second assignment mark: ");      
	scanf("%lf", &assignment2);

	average = ((test1 + test2 + assignment1 + assignment2)/4);

	printf("Your average is: %f \n\n", average);

/* Now using nested ifs the program will use the calculate the average of the entered numbers and will
   determine what the final mark is for the student. There are also if statements which check that the 
   given marks are within the restrictions (that both tests and both assignments were passed). */
	
	if (test1