#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Reading Input - Newbie question


    I am currently coding a program for an assignment involving customer orders... So far everything has been coded correct but now i have a problem when it comes to reading user input.. 2 lines are appearing on the screen without giving the user time to enter the order quantity.. This is because i am using scanf.. i tried making use of fflush(stdin) and get char() but none worked.. the following is the code which is giving me problems


    puts("\nEnter Product Details\n");
    puts("Product Name: ");
    gets(newProduct.Name);
    puts("ISBN: ");
    gets(newProduct.ISBN);
    puts("Description: ");
    gets(newProduct.Description);
    puts("Price: ");
    scanf("%f",&newProduct.Price);
    puts("Quantity in Stock: ");
    scanf("%d",&newProduct.QuantityinStock);
    printf("Supplier: ");
    gets(newProduct.Supplier);
    printf("Order Quantity: ");
    scanf("%d",&newProduct.OrderQuantity);
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    Didja read the FAQ? It has a lot of info regarding reading from the user.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo