All functions should have there own declaration and defintions. Then they should
ID: 3624232 • Letter: A
Question
All functions should have there own declaration and defintions. Then they should all be called through the main. The idea is to keep the functions seprate form the main function in case modifications are made to one function it will be easier to do so and better for readability. It is required.
The output from this program is to look EXACTLY like the example output. You will need one 2-D array to hold the items sold for each store(to be input), a 1-D array for store totals, a 1-D array for item totals, a 1-D array to hold the profit margins (to be input) and a 1-D array for the item profits. You will need a variable to hold the sum of the store totals and a variable for the total profit.
Below is the program. Thank you.
Explanation / Answer
please rate -thanks
please see your messages. the formatting is not quite done.
can you get back to me exactly how wide each column is
#include <stdio.h>
#include <conio.h>
void input(int[][4],char[][13]);
void storetotals(int[][4],int[]);
void foodtotals(int[][4],int[]);
void getprofit(double[],char[][13]);
int getgrand(int[]);
double getitemprofit(double[],int[],double[]);
void report(int[][4],int[],int[],double[],double[],double,int);
int main()
{int items[3][4],store[3]={0,0,0},food[4]={0,0,0,0};
double margin[4],profit[4],totalprofit;
char names[4][13]={"Burritos","Tacos","Tostadas","Taquitos"};
int grandtotal;
input(items,names);
getprofit(margin,names);
storetotals(items,store);
foodtotals(items,food);
grandtotal=getgrand(store);
totalprofit=getitemprofit(margin,food,profit);
report(items,store,food,margin,profit,totalprofit,grandtotal);
getch();
return 0;
}
void report(int items[][4],int store[],int food[],
double margin[],double profit[],double totalprofit,int grandtotal)
{int i,j;
printf(" El Cilantro Tacos -- -------- ----- ");
printf(" Burritos Tacos Tostadas Taquitos Store Totals ");
printf(" -------- ----- -------- -------- ------------ ");
for(i=0;i<3;i++)
{printf("Store # %d |",i+1);
for(j=0;j<4;j++)
printf("%10d",items[i][j]);
printf("%10d ",store[i]);
}
printf(" -------- ----- -------- -------- ------------ ");
printf("Item Totals ");
for(j=0;j<4;j++)
printf("%10d",food[j]);
printf("%10d ",grandtotal);
printf(" Profit Margin ");
for(j=0;j<4;j++)
printf("%10.2f",margin[j]);
printf(" Total Profit ");
printf("Item profit ");
for(j=0;j<4;j++)
printf("%10.2f",profit[j]);
printf(" %10.2f ",totalprofit);
}
double getitemprofit(double margin[],int food[],double profit[])
{int i;
double tot=0;
for(i=0;i<4;i++)
{profit[i]=margin[i]*food[i];
tot+=profit[i];
}
return tot;
}
void getprofit(double profit[],char food[][13])
{int i;
for(i=0;i<4;i++)
{printf("Enter profit margin for %s: ",food[i]);
scanf("%lf",&profit[i]);
}
}
int getgrand(int store[])
{int i,tot=0;
for(i=0;i<3;i++)
tot+=store[i];
return tot;
}
void foodtotals(int item[][4],int food[])
{int i,j;
for(i=0;i<4;i++)
for(j=0;j<3;j++)
food[i]+=item[j][i];
}
void storetotals(int item[][4],int store[])
{int i,j;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
store[i]+=item[i][j];
}
void input(int item[][4],char food[][13])
{int i,j;
for(i=0;i<3;i++)
{printf("for store # %d: ",i+1);
for(j=0;j<4;j++)
{printf("Enter number of %s: ",food[i]);
scanf("%d",&item[i][j]);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.