Recap Challenge
Part of the Fundamentals section of Coddy's C journey — lesson 15 of 63.
Challenge
EasyCreate a C program that:
- Declares and initializes:
- An integer variable
agewith value 25 - A float variable
pricewith value 19.99 - A character variable
gradewith value 'A' - A constant
MAX_SCOREwith value 100 using#define
- An integer variable
- Calculate:
- The
priceafter a 15% discount and store it in a variablediscounted_price - Convert the
discounted_priceto an integer using explicit casting, and store asrounded_price
- The
Make sure to format floating-point numbers to show exactly 2 decimal places.
Try it yourself
#include <stdio.h>
int main() {
// Declare and initialize variables
// Calculate discounted price
// Convert to integer using casting
// Print all variables
printf("Age: %d\n", age);
printf("Price: $%.2f\n", price);
printf("Discounted Price: $%.2f\n", discounted_price);
printf("Rounded Price: $%d\n", rounded_price);
printf("Grade: %c\n", grade);
printf("Max Score: %d\n", MAX_SCORE);
return 0;
}All lessons in Fundamentals
3Operators
Arithmetic OperatorsModulo OperatorIncrement/DecrementAssignment OperatorsRelational OperatorsLogical Operators Part 1Logical Operators Part 2Logical Operators Part 3Recap Challenge