example2_formatted_IO.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <cstdio>

int main() {
    int age;
    char name[50];
    float height;

    printf("Enter your name, age, and height (space-delimited): ");
    if (scanf("%49s %d %f", name, &age, &height) == 3) {
        printf("Name: %s\nAge: %d\nHeight: %.2f meters\n", name, age, height);
    } else {
        fprintf(stderr, "Error reading input\n");
    }

    return 0;
}
Back to cstdio