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);
您可以在scanf()
之后尝试使用getchar()
scanf()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.