Hi, here you will find a program which taking some inputs calculates the sales of 5 items on daily and weekly basis. Prevously I wrote it with no function, and it was quite a very long program, 9 A4 sheets, but this is written by using a function. As long as I calculate the sales of a day, it's all right, but when I try to do it for the week, I get a strange value, namely, 0.0000.
Why???
Here the code:
/*Program calculating the daily and weekly sales of 5 items*/
#include<stdio.h>
/*Prototype function daily_sales*/
float daily_sales(int day_number,int item , float quantity1, float quantity2,float quantity3, float quantity4, float quantity5,float value1,float value2, float value3,float value4,float value5, float val1, float val2,float val3, float val4, float val5, float Tot_value);
/*End Prototype function daily_sales */
float main ()
{
int day ;
int id;
float q1,q2,q3,q4,q5;
float value1_day1 = 0;
float value2_day1 = 0;
float value3_day1 = 0;
float value4_day1 = 0;
float value5_day1 = 0;
float value1_day2 = 0;
float value2_day2 = 0;
float value3_day2 = 0;
float value4_day2 = 0;
float value5_day2 = 0;
float value1_day3 = 0;
float value2_day3 = 0;
float value3_day3 = 0;
float value4_day3 = 0;
float value5_day3 = 0;
float value1_day4 = 0;
float value2_day4 = 0;
float value3_day4 = 0;
float value4_day4 = 0;
float value5_day4 = 0;
float value1_day5 = 0;
float value2_day5 = 0;
float value3_day5 = 0;
float value4_day5 = 0;
float value5_day5 = 0;
float value1_day6 = 0;
float value2_day6 = 0;
float value3_day6 = 0;
float value4_day6 = 0;
float value5_day6 = 0;
float value1_day7 = 0;
float value2_day7 = 0;
float value3_day7 = 0;
float value4_day7 = 0;
float value5_day7 = 0;
float val1_day1 = 0;
float val2_day1 = 0;
float val3_day1 = 0;
float val4_day1 = 0;
float val5_day1 = 0;
float val1_day2 = 0;
float val2_day2 = 0;
float val3_day2 = 0;
float val4_day2 = 0;
float val5_day2 = 0;
float val1_day3 = 0;
float val2_day3 = 0;
float val3_day3 = 0;
float val4_day3 = 0;
float val5_day3 = 0;
float val1_day4 = 0;
float val2_day4 = 0;
float val3_day4 = 0;
float val4_day4 = 0;
float val5_day4 = 0;
float val1_day5 = 0;
float val2_day5 = 0;
float val3_day5 = 0;
float val4_day5 = 0;
float val5_day5 = 0;
float val1_day6 = 0;
float val2_day6 = 0;
float val3_day6 = 0;
float val4_day6 = 0;
float val5_day6 = 0;
float val1_day7 = 0;
float val2_day7 = 0;
float val3_day7 = 0;
float val4_day7 = 0;
float val5_day7 = 0;
float Tot_value_day1 = 0;
float Tot_value_day2 = 0;
float Tot_value_day3 = 0;
float Tot_value_day4 = 0;
float Tot_value_day5 = 0;
float Tot_value_day6 = 0;
float Tot_value_day7 = 0;
float Tot_week = 0;
printf("Please enter a value -1 to 7- to end\n");
scanf("%d",&day);
while(day<=7)
{
printf("Please enter the day number -1 to 7 - to end\n");
scanf("%d",&day);
switch(day) /*Start switch day 1*/
{
case 1:/*Start case day 1*/
daily_sales(day,id,q1,q2,q3,q4,q5,value1_day1,value2_day1,value3_day1,value4_day1,value5_day1,val1_day1,val2_day1,val3_day1,val4_day1,val5_day1,Tot_value_day1);
break;/*break case1 day*/
printf("Please enter another day number\n");
scanf("%d",&day);
case 2:/*Start case day 2*/
daily_sales(day,id,q1,q2,q3,q4,q5,value1_day2,value2_day2,value3_day2,value4_day2,value5_day2,val1_day2,val2_day2,val3_day2,val4_day2,val5_day2,Tot_value_day2);
break;/*break case1 day 2*/
printf("Please enter another day number\n");
scanf("%d",&day);
case 3:/*Start case day 3*/
daily_sales(day,id,q1,q2,q3,q4,q5,value1_day3,value2_day3,value3_day3,value4_day3,value5_day3,val1_day3,val2_day3,val3_day3,val4_day3,val5_day3,Tot_value_day3);
break;/*break case1 day 3*/
printf("Please enter another day number\n");
scanf("%d",&day);
case 4:/*Start case day 4*/
daily_sales(day,id,q1,q2,q3,q4,q5,value1_day4,value2_day4,value3_day4,value4_day4,value5_day4,val1_day4,val2_day4,val3_day4,val4_day4,val5_day4,Tot_value_day4);
break;/*break case1 day4*/
printf("Please enter another day number\n");
scanf("%d",&day);
case 5:/*Start case day 5*/
daily_sales(day,id,q1,q2,q3,q4,q5,value1_day5,value2_day5,value3_day5,value4_day5,value5_day5,val1_day5,val2_day5,val3_day5,val4_day5,val5_day5,Tot_value_day5);
break;/*break case1 day5*/
printf("Please enter another day number\n");
scanf("%d",&day);
case 6:/*Start case day 6*/
daily_sales(day,id,q1,q2,q3,q4,q5,value1_day6,value2_day6,value3_day6,value4_day6,value5_day6,val1_day6,val2_day6,val3_day6,val4_day6,val5_day6,Tot_value_day6);
break;/*break case day6*/
printf("Please enter another day number\n");
scanf("%d",&day);
case 7:/*Start case day 7*/
daily_sales(day,id,q1,q2,q3,q4,q5,value1_day7,value2_day7,value3_day7,value4_day7,value5_day7,val1_day7,val2_day7,val3_day7,val4_day7,val5_day7,Tot_value_day7);
break;/*break case day7*/
printf("Please enter another day number\n");
scanf("%d",&day);
default:
printf("The sales for this week are over\n");
break;
}/*End days switch*/
}/*End outer while cycle*/
Tot_week = Tot_value_day1 + Tot_value_day2 + Tot_value_day3 + Tot_value_day4 + Tot_value_day5 + Tot_value_day6 + Tot_value_day7;
printf("The total value for this week is: %f\n", Tot_week);
return 0;
}
/*Definition function daily_sales*/
float daily_sales(int day_number,int item , float quantity1, float quantity2,float quantity3, float quantity4, float quantity5,float value1,float value2, float value3,float value4,float value5, float val1, float val2,float val3, float val4, float val5, float Tot_value)
{
printf("Please enter the id number - 1 to 5 - to end\n");
scanf("%d",&item);
while(item<=5)/*Start while case 1*/
{
printf("All right!! Please enter the id number - 1 to 5 - to end\n");
scanf("%d",&item);
switch(item)/*Start switch id day 1*/
{
case 1:
printf("Please enter the quantity\n");
scanf("%f",&quantity1);
value1 = quantity1 * 10;
val1 += value1;
printf("The value of id 1 for day %d is: %f\n",day_number, val1);
break;
case 2:
printf("Please enter the quantity\n");
scanf("%f",&quantity2);
value2 = quantity2 * 20;
val2 += value2;
printf("The value of id 2 for day %d is: %f\n",day_number, val2);
break;
case 3:
printf("Please enter the quantity\n");
scanf("%f",&quantity3);
value3 = quantity3 * 30;
val3 += value3;
printf("The value of id 3 for day %d is: %f\n",day_number, val3);
break;
case 4:
printf("Please enter the quantity\n");
scanf("%f",&quantity4);
value4 = quantity4 * 40;
val4 += value4;
printf("The value of id 4 for day %d is: %f\n",day_number, val4);
break;
case 5:
printf("Please enter the quantity\n");
scanf("%f",&quantity5);
value5 = quantity5 * 50;
val5 += value5;
printf("The value of id 5 for day %d is: %f\n",day_number, val5);
break;
default:
printf("For now the sales are over!!\n");
break;
}/*End switch*/
}/*End while case*/
Tot_value = val1 + val2 + val3 + val4 + val5;
printf("The total value of day %d is: %f\n",day_number, Tot_value);
return Tot_value;
} /*End definition function daily_sales */
Is there anyone able to help me?
Thank you very much, indeed!!!
Fab2