Originally Posted by
Salem
Not sure what compiler you're using, or where "invalid operands to binary..
[QUOTE=Salem;1298122]Not sure what compiler you're using, or where..[/code]
I use codeblocks and ye, this code didnt gave an error since as i mentioned i played around alot and then let it be in a state, i just was to tired to rework the code, to repeat this error, but it came when i did something like sum = sum+dailyhours;
so tonight i finally got that program working, doing exactly what it was supposed to do, with the right output. feelsgoodman, all these days and hours from morning till night paid off.. was painful but necessairy to keep trying. im actual thankful, no one gave me the answer, since im supposed to solve problems in future on my own as a programmer xd. but now i could see how you would have done it/what i have could done much better,easier etc if u like, let me know
i have an example solution from the school now, so i might post that afterwards, when some ppls posted something first.
thats my code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j, enthrs, days;
float dhrs[30], avg = 0, sum = 0;
printf("The program calculates the total hours worked during\na specific period and the average length of a day.\n\n");
printf("How many days:");
scanf("%d", &days);
for(i = 1; i <= days; i++)
{
printf("Enter the working hours for day %d:", i);
scanf("%f", &dhrs[i-1]);
}
for(j = 0; j < i; j++)
{
sum = sum+dhrs[j];
avg = sum/days;
}
printf("\nTotal hours worked: %.1f\n", sum);
printf("Average length of day: %.1f\n", avg);
printf("Hours entered: ");
for(enthrs = 0; enthrs < days; enthrs++)
{
printf("%.1f ", dhrs[enthrs]);
}
return 0;
}
good night for now x)