Challenge: Book Record

Lab C Beginner 10 points

Define a struct Book with a title (one word), pages and price (a double). Read one book and print it like this:

Title: Dune
Pages: 412
Price: 9.50

Input

A title (one word), pages and price, separated by spaces.

Output

Three lines as shown.

Example

Input

Dune 412 9.5

Output

Title: Dune
Pages: 412
Price: 9.50
Sample input available Sample output available
Editor
C

Hints

Read a double with %lf.

The title is a string, so no & before b.title.

Solution explanation

The three fields live together in one Book variable and are reached with the dot.

Show solution
#include <stdio.h>

typedef struct {
    char title[50];
    int pages;
    double price;
} Book;

int main() {
    Book b;
    scanf("%s %d %lf", b.title, &b.pages, &b.price);
    printf("Title: %s\n", b.title);
    printf("Pages: %d\n", b.pages);
    printf("Price: %.2f\n", b.price);
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD