0

i hope some one can help me

#include <stdio.h>

int main(void) {
int n1;
char g;

 printf("\nPlease, Enter The Number Of Your Children: ");
 scanf("%d",&n1);

if(n1>=3)
    printf("\nYou have alot of kids!\n");
else if(n1==2)
    printf("\nYou have 2 kids\n");
else if(n1==1){
    printf("\n Boy Or Girl (g/b): ");

Here i tried to use %c but its not working it print the last line without asking me boy or girl!

    scanf("%s",&g); 

} 
if( g == 'b') 
    printf("\n You Have a little prince\n");
else
    printf("\n You have a little princess\n");


  return 0;
 } 
  • Until you've learned more, don't try to use `%c`. (I know this sounds like crazy advice, but `%c` is crazy. Actually just about everything abut `scanf` is crazy, but that's another story.) – Steve Summit Jun 29 '21 at 20:08
  • If you are reading lines of input from a user, always use `fgets` – stark Jun 29 '21 at 20:14
  • `%c` doesn't skip over leading whitespace, so you're picking up the newline character from the previous input. To guard against that, put a blank space in the format string before the `%c` specifier - `scanf( " %c", &g );`. – John Bode Jun 29 '21 at 21:15

0 Answers0