lundi 25 octobre 2021

My program only works in specific cases when it should in all

So I was trying to make a program that grades the user based on the marks they enter, it works but sometimes it doesn't like when I input 67 as marks for CSC111 and 45 as marks for CSC115 it doesn't display the grade for CSC115, but when I input 45 for both it shows the grade for both.

#include<stdio.h>
int main()
{
    char firstName[100];
    char lastName[100];
    int regNo;
    int marksCSC115;
    int marksCSC111;
    char grade11;
    char grade15;
    printf("Enter your name (first and last)> ");
    scanf("%s %s", firstName, lastName);
    printf("Enter your registration number> ");
    scanf("%d", &regNo);
    printf("Enter your marks in CSC111> ");
    scanf("%d", &marksCSC111);
    printf("Enter your marks in CSC115> ");
    scanf("%d", &marksCSC115);

    if(marksCSC111 >= 0 && marksCSC111 <= 39){
        grade11 = 'F';}
    else if(marksCSC111 >39 && marksCSC111 <= 49){
        grade11 = 'E'
    ;}
    else if(marksCSC111 >49 && marksCSC111 <= 59){
        grade11 = 'D'
    ;}
    else if(marksCSC111 >59 && marksCSC111 <= 69){
        grade11 = 'C'
    ;}
    else if(marksCSC111 >69 && marksCSC111 <= 79){
        grade11 = 'B'
    ;}
    else if(marksCSC111 >79) {
        grade11 = 'A'
    ;}
    if(marksCSC115 >= 0 && marksCSC111 <= 39){
        grade15 = 'F';}
    else if(marksCSC115 >39 && marksCSC111 <= 49){
        grade15 = 'E'
    ;}
    else if(marksCSC115 >49 && marksCSC111 <= 59){
        grade15 = 'D'
    ;}
    else if(marksCSC115 >59 && marksCSC111 <= 69){
        grade15 = 'C'
    ;}
    else if(marksCSC115 >69 && marksCSC111 <= 79){
        grade15 = 'B'
    ;}
    else if(marksCSC115 >79) {
        grade15 = 'A'
    ;}

printf("\nSTUDENT NAME: %s %s\n\nSTUDENT IDNO: %d\n\nCOURSE CODE   MARKS  GRADE\n\nCCS111         %d     %c\n\nCCS115         %d     %c",firstName,lastName, regNo, marksCSC111, grade11, marksCSC115, grade15);


}

Aucun commentaire:

Enregistrer un commentaire