Hi, this is only the second program I have ever done in C. It is for my college class, and it is driving me crazy. I think I got it all right, but for some reason on the first two imputs, it acts like you are imputting a 0, when you are just inputing a decimal number. I can't figure out why it isn't using the decimal number you enter.
Please help if you can thanks
Note: it is the profrate and trate that seem to be the problem. The input values for the two are .1 for the trate, and .2 for the profrate.
When run, the results come out as if you had entered 0 for both
Code:
/*
Project 3 program solution to the Project 1 problem.
11/03/2005
by Phil Pliuskonis
*/
#include<stdio.h>
// Function prototypes
void title(void);
void initial(void);
void inputrate(void);
void inputdata(void);
void process(void);
void unit_price(void);
void sales_cost_ammt(void);
void item_prof(void);
void output_1(void);
void totals(void);
void loop_out(void);
void high_prof(void);
void calc_ta(void);
void rpt_out(void);
// Data declarations
int tsales, tcost, tunits, ttax, tprof, hiprof, hicode, avgprof, itemprof, saleamt, costamt, code, qty, ucost, uprice;
float profrate, trate;
char more_item;
main()
{
title();
initial();
inputrate();
while (more_item !='N')
{
process();
}
calc_ta();
rpt_out();
return 0;
}
void title(void)
{
printf("\nProject 3 by: Phil Pliuskonis\n");
return;
}
void inputdata(void)
{
printf("\nInput item code: ");
scanf("%d", &code);
printf("\nInput item quantity: ");
scanf("%d", &qty);
printf("\nInput unit cost: ");
scanf("%d", &ucost);
return;
}
void inputrate(void)
{
float trate, profrate;
printf("\nInput tax rate (decimal number) : ");
scanf("%f", &trate);
printf("\nInput profit rate (decimal number) : ");
scanf("%f", &profrate);
return;
}
void initial(void)
{
tsales = tcost = tunits = hiprof = 0;
more_item = 'Y';
return;
}
void process(void)
{
inputdata();
unit_price();
sales_cost_ammt();
item_prof();
output_1();
totals();
high_prof();
loop_out();
return;
}
void unit_price(void)
{
uprice = ucost + profrate * ucost;
return;
}
void sales_cost_ammt(void)
{
saleamt = qty * uprice;
costamt = qty * ucost;
return;
}
void item_prof(void)
{
itemprof = saleamt - costamt;
return;
}
void output_1(void)
{
printf("\nCode: %d\n", code);
printf("Quantity: %d\n", qty);
printf("Unit cost: %d\n", ucost);
printf("Unit price: %d\n", uprice);
printf("Sale ammount: %d\n", saleamt);
printf("Cost ammount: %d\n", costamt);
printf("Item profit: %d\n", itemprof);
return;
}
void totals(void)
{
tsales = tsales + saleamt;
tcost = tcost + costamt;
tunits = tunits + qty;
return;
}
void high_prof(void)
{
if (itemprof > hiprof)
{
hiprof = itemprof;
hicode = code;
}
return;
}
void loop_out(void)
{
printf("\n Are there any more items to process? (Y/N): ");
fflush(stdin);
scanf("%c", &more_item);
if (more_item == 'n')
{
more_item = 'N';
}
return;
}
void calc_ta(void)
{
tprof = tsales - tcost;
avgprof = tprof / tunits;
ttax = trate * tsales;
return;
}
void rpt_out(void)
{
printf("Total sales: %d\n", tsales);
printf("Total profit: %d\n", tprof);
printf("Average profit: %d\n", avgprof);
printf("Total tax: %d\n", ttax);
printf("High profit: %d\n", hiprof);
printf("High item code: %d\n", hicode);
return;
}