i am trying to write a program that will prompt the user to enter test scores terminated by a negative number. and then find the min max and average of the scores inputted. i have gotten everything to work except the average. the assignment says i can only use variables of type "int" so my question is how to print the average to 2 decimal places using only int and not floats. this is what i have so far

        main()
{
    int number, min, max, count, sum;
    printf("Enter test scores; enter any  negative value to end list\n");

    scanf("%d", &number);
    min = number;
    max = number;
    for (count=1; count<=10; count++)
    {
        if (number>=0)
        {
        scanf("%d", &number);
        if (number < min)
            min = number;
        else if (number > max)
            max = number;


        sum = sum + number;
        count=count+1;
        scanf("%d", &number);
        }



    }
    printf("Lowest Score  = %d\n", min); 
    printf("Highest Score = %d\n", max); 
    printf("Average Score = %0.2f\n",(float)sum/count); 
}

Recommended Answers

All 4 Replies

the assignment says i can only use variables of type "int" so my question is how to print the average to 2 decimal places using only int and not floats.

Does the assignment say print 2 decimals using only ints?
Think back on you elementary math. How do you get decimal values using whole numbers?

I thought it was by using %0.2f and then writing (float)sum. We aren't allowed to use floats. Maybe use a double?

I repeat:
Think back on your elementary math. How do you get decimal values using whole numbers?

i have no idea, thanks for the help tho

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.