I keep running into a run-time error... and it says that "tp" is uninitialized... what am I missing here?
Code:
#include <stdio.h>
#pragma warning(disable:4996)
void input_sales(int [3][4]);
void input_profit_margins(int[4]);
void calc_store_totals(int [3][4],int[]);
void calc_item_totals(int [3][4],int[]);
void calc_item_profits(int[4],int[4],int[]);
int calc_total_profit(int[4]);
void print_report(int [3][4],int[3],int[4],int[4],int[4],int);
int main()
{
int sales[3][4];
int store_totals[3];
// here we go
int item_totals[4];
int profit_margins[4];
int item_profits[4];
int total_profit;
input_sales(sales);
input_profit_margins(profit_margins);
calc_store_totals(sales,store_totals);
calc_item_totals(sales,item_totals);
calc_item_profits(item_totals,profit_margins,item_profits);
total_profit = calc_total_profit(item_profits);
print_report(sales, store_totals, item_totals, profit_margins, item_profits, total_profit);
return 0;
}
void input_sales(int s[3][4])
{
int row,col;
for(row=0;row<=2;row++)
{
for(col=0;col<=3;col++)
{
printf("Enter the sales for Store #%d Item # %d\n",row+1,col+1);
scanf("%d%*c",&s[row][col]);
}
}
}
void input_profit_margins(int pm[4])
{
int item;
for (item=0; item<=3; item++) {
printf("Enter the profit margin for Item # %d\n", item+1);
scanf("%d%*c",pm[item]);
}
}
void calc_store_totals(int s[3][4],int st[])
{
int row, col;
for(row=0;row<=2;row++)
{
st[row]=0;
for(col=0;col<=3;col++)
{
st[row]+=s[row][col];
}
}
}
/*taking as inputs:
s - sales
it - item_totals (this is what we'll write to)
*/
void calc_item_totals(int s[3][4],int it[])
{
int row, col;
for (col=0; col<=3; col++) {
for (row=0; row<=2; row++) {
it[col]+=s[row][col];
}
}
/*so what's happening here is this:
*set col=0 (ie-Burritos)
*set row=0 (ie-Store#1)
*add Store 1 value for Burritos to Burritos col of item_totals
*set row=1 (ie-Store#2)
*add Store 2 value for Burritos to Burritos col of item_totals
*set row=2 (ie-Store#3)
*add Store 3 value for Burritos to Burritos col of item_totals
*set col=1 (ie-Tacos)
*set row=0 (ie-Store#1)
*add Store 1 value for Tacos to Tacos col of item_totals
get the pattern?*/
}
/*taking as inputs:
it - item_totals
pm - profit_margins
ip - item_profits (this is what we'll write to)
*/
void calc_item_profits(int it[4],int pm[4],int ip[])
{
int item;
// multiply each item by its profit_margin
// store in ip
for (item=0; item<=3; item++) {
ip[item]=it[item]*pm[item];
}
}
/*taking as input:
ip - item_profits
returning:
tp - total_profit
*/
int calc_total_profit(int ip[4])
{
int item;
int tp;
for(item=0; item<=3; item++) {
tp+=ip[item];
}
return tp;
}
/*taking as input:
s - sales
st - store_totals
it - item_totals
pm - profit_margins
ip - item_profits
tp - total_profit*/