I have this program, its mainly the program from "C programming Absolute beginner's guide" on page 263 but I just added the header file info to the program under (over main()).
#include <stdio.h>
struct bookInfo {
    char title[40];
    char author[25];
    float price;
    int pages;
};
int main()
{
    int ctr;
    struct bookInfo books[3]; // Array of three structure variables
    // Get the information about each book from the user
    for (ctr = 0; ctr < 3; ctr++)
    {
        printf("What is the name of the book #%d?\n", (ctr+1));
        gets(books[ctr].title);
        puts("Who is the author? ");
        gets(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(); //Clears last newline for next loop
    }
    // Print a header line and then loop through and print the info
    printf("\n\nHere is the collection of books: \n");
    for (ctr = 0; ctr < 3; ctr++)
    {
        printf("#%d: %s by %s", (ctr+1), books[ctr].title,
            books[ctr].author);
        printf("\nIt is %d pages and costs $%.2f", books[ctr].pages,
            books[ctr].price);
        printf("\n\n");
    }
    return 0;
}
So the program does not function as intended because it:
- It shows the inputted cost as the number of pages.
- It shows 0 as the cost.
- It doesn't ask for the pages of the book.
I have tried to just change the cost and pages to see if it would help somewhat, but nothing changed which was also weird.
What is/are the problem/problems with this program?
Edit 1: Run input log:
What is the name of the book #1?
book1
Who is the author?
adam
How much did the book cost?
100
How many pages in the book?
What is the name of the book #2?
book2
Who is the author?
adam2
How much did the book cost?
102
How many pages in the book?
What is the name of the book #3?
book3
Who is the author?
adam3
How much did the book cost?
103
How many pages in the book?
Here is the collection of books:
#1: book1 by adam
It is 100 pages and costs $0.00
#2: book2 by adam2
It is 102 pages and costs $0.00
#3: book3 by adam3
It is 103 pages and costs $0.00
Process returned 0 (0x0)   execution time : 16.934 s
Press ENTER to continue.
