Thread: Multiple printf/scanf code issue

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    8

    Multiple printf/scanf code issue

    Hello!

    I'm attempting to write another program from Let us C book.

    Below I'm pasting just a part of the code that is problematic for me:

    Code:
    main(){
        int age;
        char male, city, healthy;
        printf("what is the age of the person? ");
        scanf("%d", &age);
        printf("is the person male? ");
        scanf ("%c", &male);
        printf("is the person living in the city? ");
        scanf("%c", &city);
        printf("is the person of excellent health? ");
        scanf("%c", &healthy);
    }
    The problem is that when i execute the code, the first printf function is displayed and when i enter the value, the second and third printf function are displayed at the same time, while I'd like the next printf function to be displayed only after i had answered the question before.

    Is there anything wrong in the code that prevents that from happening? Or maybe I need some more advanced commands that I haven't read about yet?

    I'm using Code::Blocks to compile the program.

    Thank you in advance!

  2. #2

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    8
    Thank you for help, i need to look better next time!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple scanf calls skip printf lying between them
    By namandixit in forum C Programming
    Replies: 7
    Last Post: 04-02-2014, 08:32 PM
  2. printf() and scanf()
    By homeyg in forum C Programming
    Replies: 1
    Last Post: 02-06-2006, 10:43 PM
  3. scanf and printf
    By gmanUK in forum C Programming
    Replies: 5
    Last Post: 11-25-2005, 03:03 PM
  4. printf and scanf
    By studentc in forum C Programming
    Replies: 3
    Last Post: 06-11-2004, 03:07 PM
  5. something about printf (or maybe scanf)
    By netboy in forum C Programming
    Replies: 4
    Last Post: 06-11-2002, 10:26 PM