0

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); 
}

Edited by Dani: Fixed formatting

2
Contributors
4
Replies
7
Views
4 Years
Discussion Span
Last Post by cali_kid
0

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?

Edited by WaltP: n/a

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.