I'm attempting to write a small program that a user input book information in the "struct bookinfo" and then print what user write.
I accepted some advice in my past question. so I modified my program but It is still not working problem is that my program doesn't go to next question. If I put a character in integer variable It goes to next question but skip next question again!
here is my code
#include <stdio.h>
#include <stdlib.h>
struct bookInfo {
char title [40];
char author [25];
float price;
int pages;
};
main()
{
int ctr;
struct bookInfo books[3];
for (ctr = 0 ; ctr< 3; ctr++)
{
printf("What is the name of the book #%d?\n", (ctr+1));
scanf( " %s", books[ctr]. title);
puts("who is the author?");
scanf(" %s", books[ctr].author);
puts("How much did the book cost? ");
scanf("%f", &books[ctr].price);
puts("How many pages in the book? ");
scanf("%d", &books[ctr].pages);
getchar();
}
output is Here.
What is the name of the book #1?
cosmos
who is the author?
kalcaygon
How much did the book cost?
14.99
and then, my program doesn't go to next question. but when I put a character, it go to next question. but skip next input like this
What is the name of the book #1?
cosmos
who is the author?
kalcaygon
How much did the book cost?
14.99
d
How many pages in the book?
who is the author?
How much did the book cost?