Sunday 15 April 2012

c - Getting several inputs from users using scanf -



c - Getting several inputs from users using scanf -

i having problem here. trying several inputs user , calculate total input , average depending on number of days has worked. example, if worked 10 days, when types 10, programme inquire him come in working hours 10 days. iteratearray array can hold 30 days max , variable days, holds number of days entered. how can values using scanf?

int main(void){ printf("the programme calculates total hours worked during\n"); printf("a specific period , average length of day.\n\n"); printf("how many days:"); scanf("%d",&days); do{ if(i==days){ break; i++; } else{ printf("enter working hours day %d:",++i); scanf("%f",&iteratearray[0]); } }while(i<days); }

i think looking this:

#include <stdio.h> #include <stdlib.h> int main(){ int days, daycount; double iteratearray[30], totalwork = 0, averagework = 0; printf("the programme calculates total hours worked during\n"); printf("a specific period , average length of day.\n\n"); printf("how many days: \n>"); scanf(" %d", &days); if (days > 30) { printf("you can't work longer 30 days!"); exit(0); } for(daycount = 0; daycount < days; daycount++) { printf("enter working hours day %d:", daycount+1); scanf(" %lf", &iteratearray[daycount]); totalwork += iteratearray[daycount]; } averagework = totalwork / days; printf("\nthe total hours worked is: %.2lf\n", totalwork); printf("the average length of day is: %.2lf\n", averagework); homecoming 0; }

c

No comments:

Post a Comment