A percentage program that compiles but lies

The starter program compiles successfully but does not print the intended percentage. Explain its actual value, then replace the constants with checked input of earned and possible. Valid input satisfies 0 <= earned <= possible <= 10000 and possible > 0. Print percent=P with two digits after the decimal point, or invalid for missing/out-of-range input.

    Explain both where you introduce floating-point arithmetic and why the validation must occur before division. Include tests for 3/8, zero earned, full credit and a zero possible value.

Assume every integer token supplied is representable in int.

#include <stdio.h>
int main(void)
{
    int earned = 3;
    int possible = 8;
    double percent = earned / possible * 100;
    printf("%.2f\n", percent);
    return 0;
}

