I've been over this code several times but still cannont figure out why after the first time, it always prints "Add in sale? Y/N:" twice. Any ideas?
void PrintHeader();
int TotalSales();
float OverallProfit(float totalvalue, float drinkcost, int runningcost);
float CalculateCosts();//Not used yet
int IncentiveCheck(); //Not used yet
#include <stdio.h>
#include <stdlib.h>
int main()
{
int teasold=0, coffeesold=0, hotchocsold=0, lattesold=0;
int flatwhitesold=0, totalsales=0, drinktype=0;
float tea=1.00, coffee=1.50, hotchoc=2.00, chailatte=1.75, flatwhite=2.20;
float totalvalue=0, runningcost=10.00, totalprofit=0, drinkcost, incentive, overallprof;
float teacost=0.20, coffeecost=0.25, hotchoccost=0.50, lattecost=0.25, flatwhitecost=0.50;
char yesno, dollar='$';
PrintHeader();
while (totalsales<500)
{
printf("\nAdd In Sale? Y/N: ");
scanf("%c", &yesno);
if ((yesno=='Y') || (yesno=='y'))
{
totalsales=TotalSales(totalsales);
printf("\nDrink type?\n\n");
printf("1. Tea\n");
printf("2. Coffee\n");
printf("3. Hot Chocolate\n");
printf("4. Chai Latte\n");
printf("5. Flat White\n\n");
printf("You choose: ");
scanf("%d", &drinktype);
switch (drinktype)
{ case (1): teasold=teasold+1;
break;
case (2): coffeesold=coffeesold+1;
break;
case (3): hotchocsold=hotchocsold+1;
break;
case (4): lattesold=lattesold+1;
break;
case (5): flatwhitesold=flatwhitesold+1;
break;
default: printf("Please choise a valid option");
break;
}
}
else if ((yesno=='N') || (yesno=='n'))
{
printf("\nTotal Sales: %d\n\n", totalsales);
printf("Total Tea Sales: %d\n", teasold);
printf("Total Coffee Sales: %d\n", coffeesold);
printf("Total Hot Chocolate Sales: %d\n", hotchocsold);
printf("Total Chai Latte Sales: %d\n", lattesold);
printf("Total Flat While Sales: %d\n\n", flatwhitesold);
totalvalue=tea*teasold+coffee*coffeesold+hotchoc*hotchocsold+chailatte*lattesold+flatwhite*flatwhitesold;
printf("Total value of days sales: %.2f\n", totalvalue);
drinkcost=teasold*teacost+coffeesold*coffeecost+hotchocsold*hotchoccost+lattesold*lattecost+flatwhitesold*flatwhitecost;
printf("Running cost on drinks: %.2f\n\n", drinkcost);
overallprof = OverallProfit(totalvalue, drinkcost, runningcost);
printf("Total profit on days sales: %.2f\n\n", overallprof);
if ((lattesold>20) || (flatwhitesold>20))
{
incentive=totalprofit/100*2;
printf("Incentive target met\n");
printf("Incentive payout %c%.2f", dollar, incentive);
}
else
{
printf("No incentive targets met\n");
printf("Incentive payout %c0.00", dollar);
}
getch();
}
}
getch();
}
void PrintHeader()
{
printf("-------------------\n");
printf("CHEAPO DRINKS CO cU\n");
printf(" Evesham\n");
printf("-------------------\n\n");
}
int TotalSales(totalsales)
{
totalsales=totalsales+1;
return totalsales;
}
float OverallProfit (float totalvalue, float drinkcost, int runningcost)
{
int temp;
temp=totalvalue-drinkcost-runningcost;
return temp;
}