C Programing Boolean expression -
i trying write code in c programming prompting people answer boolean yes
or no
question run action accordingly. instead of if
or switch
.
include <stdlib.h> include <stdio.h> int main() { int children; int age; printf("please enter age"); scanf("%d", age); printf("are married?, please enter y yes , n no"\n\n); scanf("%s", mstatus); if (mstatus y or y) { printf("how many children have: \n\n") scanf("%d", children) } return 0; }
scanf("%d", age);
should :
scanf("%d", &age); // missing ampersand here.
printf("are married?, please enter y yes , n no"\n\n);
to
printf("are married?, please enter y yes , n no\n\n"); // newlines should inside format string
though other answer addresses issue, believe using switch-case
better here :
printf("are married?, please enter y yes , n no\n\n"); scanf("%c",&c); switch(c) { case('y'): printf("how many children have: \n\n"); scanf("%d",&children); // remember put ampersand here break; case('n'): printf("enjoy bachelorhood\n"); break; default: printf("choice neither y nor n, confused marriage?\n"); }
Comments
Post a Comment