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