# changing data output from whole number to float two decimal places

This is a discussion on changing data output from whole number to float two decimal places within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> //Write a function, invoked from the main function which will allow scanning data into the array. void input(int ...

1. ## changing data output from whole number to float two decimal places

Code:
```#include<stdio.h>
//Write a function, invoked from the main function which will allow scanning data into the array.
void input(int examscores[5][4])
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
printf("input grades of student %d for exam %d\n: ",i+1,j+1);
scanf("%d",&examscores[i][j]);
}
printf("\n\n");
}
}
//Write a function that will calculate and output the average (to 2 decimal places)
//for each student appropriately labeled.
void average(int examscores[5][4])
{
int i,j;
int sum=0;
double avg_student;
for(i=0;i<5;i++)
{
printf("Student %d's average score is\n ",i+1);
sum=0;
for(j=0;j<4;j++)
{
sum=sum+examscores[i][j];
}
avg_student=sum/4;
printf("%.2f\n",avg_student);
}
}
//4) Write a function that will calculate and output the average for each of the 4 exams
//appropriately labeled.
void overall_average(int examscores[5][4])
{
int i,j;
int sum;
double avg;
for(j=0;j<4;j++)
{
printf("\nExam %d Average: ",j+1);
sum=0;
for(i=0;i<5;i++)
{
sum=sum+examscores[i][j];
}
avg=sum/5;
printf("%2f",avg);
}
}
//Write a function that will output the original entry data appropriately labeled.
//There should be column headings for the exam number and row labels for the student number as shown:
void output(int examscores[5][4])
{
int i,j;
printf("\n  Exam 1 Exam 2 Exam 3 Exam 4");
for(i=0;i<5;i++)
{
printf("\n%d   ",i+1);
for(j=0;j<4;j++)
{
printf("%d \t",examscores[i][j]);
}
}
}
int main(void)
{
//Create a 2 dimensional array (5X4 (int type)) which can hold 4 exam scores for each of 5 students.
int examscores[5][4];
input(examscores);
average(examscores);
printf("\n");
overall_average(examscores);
printf("\n");
output(examscores);
printf("\n");
getchar();
return 0;
}```
my output for these scores comes out in whole numbers. How do I get it to read out 2 decimal places to the left?

2. You have to use floating point numbers.

3. like %2f rather than %d's or float rather and int

4. Yes that's half of it.
Hint on the other half of it: sum/4 is an int, but sum/4.0f is a float