Menu
Coddy logo textTech

Recap Challenge

Part of the Fundamentals section of Coddy's C journey — lesson 15 of 63.

challenge icon

Challenge

Easy

Create a C program that:

  1. Declares and initializes:
    • An integer variable age with value 25
    • A float variable price with value 19.99
    • A character variable grade with value 'A'
    • A constant MAX_SCORE with value 100 using #define
  2. Calculate:
    • The price after a 15% discount and store it in a variable discounted_price
    • Convert the discounted_price to an integer using explicit casting, and store as rounded_price

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