Please I need help to compare if it's yes or no | Sololearn: Learn to code for FREE!

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; }

c

4/26/2021 9:52:26 PM

CAPSPY

2 Answers

New Answer

+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

0

Thanks