My code is not working. It is not executing grades. So please help me | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

My code is not working. It is not executing grades. So please help me

#include <stdio.h> #include<conio.h> int main() { int salary,allow; float hra,da,pf,total; char grade; printf("Hello Everyone, This is a program to find the salary"); printf("\n Please Enter Your Basic Salary"); scanf("%d",&salary); printf("Please enter your grade"); scanf("%d",&grade); hra=0.2*salary; da=0.5*salary; pf=0.11*salary; printf("Your HRA is %f",hra); printf("Your DA is %f",da); printf("Your PF is %f",pf); if(grade=="A"||grade=="a"){ allow=1700; printf("Your allow amount is 1700"); } else if(grade=="B"||grade=="b"){ allow=1500; printf("Your allow amount is 1500"); } else{ allow=1300; printf("Your allow amount is 1300"); } total=salary+hra+da+allow-pf; printf("Your total salary is %f",total); getch(); }

16th Aug 2019, 4:36 AM
Aryan Grover
Aryan Grover - avatar
2 Answers
+ 4
scanf("%c", grade);
16th Aug 2019, 6:39 AM
Gordon
Gordon - avatar
+ 1
Your grade is of character data type..And character should be defined in single quotes 'a' ..In your if statement you have compared grade with string not a character..Double quotes are used for defining string constant.. Just remove double quotes and use single quotes
16th Aug 2019, 5:59 AM
Alaska
Alaska - avatar