Please I need help to compare if it's yes or no | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please I need help to compare if it's yes or no

#include <stdio.h> #include <stdlib.h> int main() { int salary; double rate; printf("Enter the payrate: "); scanf("%f", &rate); char monthly[10]; printf("Are you paid monthly? yes / no\n"); scanf("%s", &monthly); if(monthly=='yes'){ salary = rate * 30; printf("%f", salary); } else if(monthly=='no'){ salary = rate; printf("%f", salary); } return 0; }

26th Apr 2021, 9:52 PM
CAPSPY
CAPSPY - avatar
2 Answers
+ 4
You should put strings in double quotes. You can't compare strings using == Use strcmp from <string.h> to compare strings When you use == on C string, you compare adresses, not actual string
26th Apr 2021, 9:54 PM
Michal Doruch
0
Thanks
27th Apr 2021, 5:10 AM
CAPSPY
CAPSPY - avatar