0
#include <stdio.h>
int main()
{
    int sc;
    int m;
    printf("Enter you marks in science\n");
    scanf("%d", &sc);
    printf("Enter your marks in math\n");
    scanf("%d", &m);

    if(sc>=36 , m>=36){
        printf("Congratulations, you have passed our exam and you have won a prize money of Rs 45!!!\n");/*those who have got more than 36 marks in both science and maths exams shall recieve 45 Rupees as a prize*/
    }
    else if (sc>=36, m<36){
        printf("Congratulations,you have passed our science exam and you have won a prize money of Rs 15!!!\n");/*those who have got more than 36 marks in science and lesser than 36 marks in maths shall recieve 15 Rupees*/
    }
    else if (sc<36, m>=36){
        printf("Congratulations,you have passed our maths exam and you have won a prize money of Rs 15!!!\n");
    }/*those who have got more than 36 marks in maths and lesser than 36 marks in science shall recieve 15 Rupees.*/
    else {
        printf("Sorry, but you failed both our exams. Work harder and try again next year!!!\n");
    }//those who got lesser than 36 marks in both subjects shall get no prize.

    return 0;
}

The image of the code and the error that occured <---Image for reference

So i am a beginner to the C language. I was working on a simple project and when i ran the project an error occurred.

The project is about awarding a prize to people who have passed in 2 of their exams( 36+marks in science and maths).

One of the else statements had a condition that if sc(variable) is lesser than 36 and m variable is lesser then 36, the following text had to be printed: Sorry, but you failed both our exams. Work harder and try again next year!!!

However the compiler assumes sc is greater than 36 and either prints the first statement or the second statement depending upon the value of m.

Could anyone please clarify this issue? Thanks in advance!!

Anonymous
  • 1
  • 2

0 Answers0