-4

It was a question to simply compare and reward the user according to input provided. I tried to improvise it a bit but it is not executing properly. Kindly provide me the insights about this code.

 void main()
{
char sci,math;
/*printf("Disclaimer: 1 for Yes, 0 for No \n");*/
printf("Did you passed maths? (y/n) \n");
scanf(" %c",&math);
printf("Did you passed science? (y/n) \n");
scanf(" %c",&sci);

if(math=="y" && sci=="y")
    {
        printf("Congratulations!! You have been awarded Rs.45 \n");
    }
else if(math=="y" && sci=="n")
    {
        printf("Congratulations!! You have been awarded Rs.15 \n");
    }
else if(math=="n" && sci=="y")
    {
        printf("Congratulations!! You have been awarded Rs.10 \n");
    }
else
    {
        printf("Sorry No awards better luck next time \n");
    }
getchar();
}
  • 2
    If you are asking about errors/warnings wouldn't it be common sense to show the actual error/warning messages? One issue is that `"y"` is a string whereas you need a char `'y'` – kaylum Jun 02 '22 at 06:37
  • What warnings do you get? What part of those warnings are not clear? Is it about comparing integer with pointers? Hint: `"y"` is a string that decays to its address, `'y'` is a `char` (well, actually an `int` but that doesn't matter now). – Gerhardh Jun 02 '22 at 06:38
  • Yes it's showing that comparison between pointer and integer. – Nikhil Manikpuri Jun 02 '22 at 06:40
  • @kaylum now it's working thanks guys. Didin't knew about `"y"` and `'y'` being different. – Nikhil Manikpuri Jun 02 '22 at 06:50

0 Answers0