0

I need help please. I need to design a program that allows a user to enter his or her marks for the coursework and final exams. The program will calculate the final mark and determine the grade gotten. When I tried to run the program, it only went up to the final mark calculation and its not displaying the grades. Your help will be greatly appreciated.

this is my code:

#include<stdio.h>

static int count=4;
float testmark[3];
static int i = 4;
static float mark;
float tassmark,assmark,ocm,average1,average2;
int main(){
puts("FINAL SEMESTER GRADE CALCULATOR");
for(count=1;count<5;count++){
float sum;
printf("for test %d you have:",count);
scanf("%f",&mark);
sum= sum+ mark;
average1 = sum/4;
}
printf("\nAverage test mark is %0.2f:",average1);

puts("\n\nTOTAL COURSEWORK MARK CALCULATION:\n");
for(i=1;i<5;i++){
    printf("Enter your mark for assignment %d:",i);
    scanf("%f",&assmark);
    tassmark=tassmark+assmark;
    average2 = tassmark/4;
    }
    printf("\nAverage for assignments is %0.2f:",average2);

puts("\n\nOVERAL COURSEWORK MARK");
ocm=(average1+average2)/2;
printf("\nYour coursework mark is %0.2f:\n" ,ocm);
float exammark,Finalmark;
printf("\n\nEnter your exam mark:");
scanf("%f",&exammark);
Finalmark=(ocm+exammark)/2;
printf("\n\nYou Final mark is %0.2f:",Finalmark);
static char grade='A';
switch(grade){
case 'A+':
    if(Finalmark<=49){
            printf("F");
            printf("FAIL");}
            break;
case 'A':
    if(Finalmark<=53){
        printf("C-");
        printf("Third Class");}
        break;
case '3':
    if(Finalmark<=56){
    printf("C");
    printf("Third Class");
    }
    break;
case '4':
    if(Finalmark<=60){
        printf("C+");
        printf("Third Class");}
        break;
case '5':
    if(Finalmark<=64){
            printf("B-");
            printf("Lower Second Class");}
            break;
case '6':
    if(Finalmark<=69){
      printf("B");
      printf("Upper Second Class");}
      break;
case '7':
    if(Finalmark<=74){
        printf("B+");
        printf("Upper Second Class");
        }
        break;
case '8':
    if(Finalmark<=80){
            printf("A-");
            printf("First Class");}
            break;
case '9':
    if(Finalmark<=90){
            printf("A");
            printf("First Class");}
            break;
case '10':
    if(Finalmark<=100){
        printf("A+");
        printf("DISTINCTION");}
        break;
default:
    printf("You don't have a valid coursework mark");

return 0;
}
}
SomeBody
  • 7,515
  • 2
  • 17
  • 33

1 Answers1

0

In the following you:

  • declare an integral variable, grade, and assign it the numeric value that relates to the character A in your platform's encoding (and you declare it static, which there's no reason for);
  • branch based on the value stored in grade, which means you always branch to case 'A' because that's the only value you've assigned; and
  • print something only if the final mark is less than or equal to 53.
static char grade='A';
switch(grade){
...
case 'A':
    if(Finalmark<=53){
        printf("C-");
        printf("Third Class");}
        break;

So what you're doing is exactly the same as not using a switch, not including any of the other cases and not declaring grade at all.

switch takes an integral value and branches to whichever case statement has that value. That's all it does.

Your program appears not have a purpose for a switch and it's unclear to me what you were trying to do with it. It looks like you probably just want the if statements.

Tommy
  • 99,986
  • 12
  • 185
  • 204