0
0
Cprogramming~15 mins

Using scanf for input - Mini Project: Build & Apply

Choose your learning style9 modes available
Using scanf for input
📖 Scenario: You are creating a simple program that asks a user for their age and height.
🎯 Goal: Build a C program that uses scanf to read an integer and a float from the user.
📋 What You'll Learn
Use scanf to read an integer value for age
Use scanf to read a float value for height
Print the values back to the user
💡 Why This Matters
🌍 Real World
Many programs need to get information from users, like age or height, to personalize the experience.
💼 Career
Understanding how to read user input with <code>scanf</code> is a basic skill for C programmers working on interactive applications.
Progress0 / 4 steps
1
Create variables for age and height
Declare an integer variable called age and a float variable called height.
C
Need a hint?

Use int for whole numbers and float for decimal numbers.

2
Use scanf to read age
Add a printf statement to ask the user to enter their age. Then use scanf with "%d" to read the integer into age.
C
Need a hint?

Remember to use &age to pass the address to scanf.

3
Use scanf to read height
Add a printf statement to ask the user to enter their height. Then use scanf with "%f" to read the float into height.
C
Need a hint?

Use %f to read a float value with scanf.

4
Print the age and height
Use printf to display the message: Your age is followed by age, and on the next line, Your height is followed by height with 2 decimal places.
C
Need a hint?

Use %d for integers and %.2f to show float with two decimals in printf.