I'm currently trying to create a small program that gets the user to enter 5 values, which are then saved in an array, and then the program calculates the average and displays it.
Here is what I have so far, it works as far as getting the user to enter the values however I have no idea how to get it to find out the sum of the values and then calculate the average. I have put in what I thought it should be but it is throwing up the following errors when I compile it.
'+' : pointer addition requires integral operand
'=' : cannot convert from 'float' to 'int (__cdecl *)(const char *,...)'
Can somebody please point me in the direction of a solution.
Thanks very much.
#include <stdio.h>
int main()
{
char str[5][20];
int i;
float sum;
float average;
for (i=0;i<5;i++)
{
printf("\nEnter value %d:",i+1);
fgets(str[i],20,stdin);
}
printf("Item # - Value");
for(i=0;i<5;i++)
{
printf("\n%d\t - %s",i+1,str[i]);
}
//problem start
for(i=0;i<5;i++)
{
sum = sum + str[i];
}
average = sum/5;
printf=("%f",average);
//problem end
return 0;
}