what's wrong about this?
why when i compile,it come out expected primary-expression?
what is that?

#include<stdio.h>
#include<conio.h>
main()
{
     float Lab,Mid,Pro,Quiz,Final,Total;

     printf("\nEnter your mark for Lab:");
     scanf("%f",&Lab);
     printf("\nEnter your mark for Mid Exam:");
     scanf("%f",&Mid);
     printf("\nEnter your mark for Quiz:");
     scanf("%f",&Quiz);
     printf("\nEnter your mark for Project:");
     scanf("%f",&Pro);
     printf("\nEnter your mark for Final Exam:");
     scanf("%f",&Final);

     Total=(10/100.0)*Lab+(15/100.0)*Mid+(5/100.0)*Quiz+(20/100.0)*Pro+(50/100.0)*Final;


     if(Total>=35)
       printf("\nyou are passed");
     else
       printf("\nyou are failed");

     if(Total>=80)
       {
       printf("\nyour is grade A",Total);
       printf("\nwell done");
       }
     else if(Total>=75)
       {
        printf("\nyour grade is A-,%f",Total);
        }
     else
       {
        printf("\nyou don't get A-,%f",Total);
        }
     else if(Total>=70)
       {
        printf("\nyour grade is B+,%f",Total);
        }
     else
       {
        printf("\nyou don't get B+,%f",Total);
        }
      else if(Total>=65)
       {
        printf("\nyour grade is B,%f",Total);
        }
      else
       {
        printf("\nyou don't get B,%f",Total);
        }
       else if(Total>=60)
       {
        printf("\nyour grade is B-,%f",Total);
        }
      else 
       {
        printf("\nyou don't get B-,%f",Total);
        }
      else if(Total>=55)
       {
        printf("\nyour grade is C+,%f",Total);
        }
      else 
       {
        printf("\nyou don't get C+,%f",Total);
        }                           
      else if(Total>=50)
       {
        printf("\nyour grade is C,%f",Total);
        }
      else
       {
        printf("\nyou don't get C,%f",Total);
        }
      else if(Total>=45)
       {
        printf("\nyour grade is C-,%f",Total);
        }
      else
       {
        printf("\nyou don't get C-,%f",Total);
        }
      else if(Total>=40)
       {
        printf("\nyour grade is D+,%f",Total);
        }
      else
       {
        printf("\nyou don't get D+,%f",Total);
        }
      else if(Total>=35)
       {
        printf("\nyour grade is D,%f",Total);
        }
      else 
       {
        printf("\nyou don't get D,%f",Total);
        }
                                                                                                                                                                                                                                          
     getch();
     return 0;
     }

Recommended Answers

All 4 Replies

printf("\nyour is grade A",Total);

Take a look at that one. Figure what are you missing.

When you post code you need to wrapped around code tags to present it in a proper format. See here.

Well,It also gives me an error.

syntax error before else

every where when you have else statements coming ahead of else if statements.

May be we can alter the structure of the program , if suppose you have a candidate getting less than 35, you still get into the if block

if(Total>=80)
.
.

here and check for grades.

I also don't under the rationale behind the statements like

printf("\nyou don't get A-,%f",Total);
.
.
printf("\nyou don't get B,%f",Total);
.
.
printf("\nyou don't get C+,%f",Total);

I would rather care for my grades than "you don't get" thing.

1st approach:
I would rather have a huge if block which checks whether the toal is greater than 35 and then calculate the grades.

const int MINIMUM_PASS_MARKS = 35;
if (total >= MINIMUM_PASS_MARKS) {
    /* and then go on checking for a valid grade*/
}
else {
/* failed*/
}

Option 2 :
Well ,you have a set grade for any given marks and a definite increment (5 in your case), So we make an array which holds
marks[] and another array which hold your grades[],it would make things simpler.
Something like this

#include<stdio.h>

int main(void) {
    const int MAX_MARKS = 100;
    const int mark_range[] = {80, 75, 70, 65, 60, 55, 50, 45, 40, 35};
    const char *grades[] = {"A", "A-", "B+", "B", "B-","C+", "C", "C-",
                     "D+", "D"};
    int total = 0;
    int i = 0;
    int divisons = sizeof (mark_range) / sizeof mark_range[0];
    int passed = 0; /*let 0 represent fail*/
    
    printf("Enter your total ");
    if (scanf("%d", &total) == 1) {
        printf("Your total is %d", total);
            /*Loop through to get your grade*/ 
            for ( i = 0; i < divisons; i++) {
            if (total >= mark_range[i] && total <= MAX_MARKS) {

                printf("\nYour grade is %s",grades[i]);
                passed = 1;
                break;
            }
         }
         if (passed == 0)
             printf("\nSorry, you failed.");
    }
    else
        fprintf(stderr, "Error in input");
    return 0;
}

Give them a rude shock if someone enters marks > 100:twisted:
and we don't use non standard headers (aka conio.h and the getch() function)

here is the proper code

Thanks all you people help...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.