I'm not sure why, but after I give the input when it prompts me, my program ends.
Here is my program:
Code:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main ()
{
int choice;
double app=0;
double tom=0;
double let=0;
double cuc=0;
double appcost=0;
double tomcost=0;
double letcost=0;
double cuccost=0;
int counter;
char cancel[20];
double total=0;
do
{
printf("MAIN MENU\n"// The main menu
"============\n"
"Option Action\n"
"------ ------------------------------------------\n"
" A - Purchase apples\n"
" C - Purchase cucumbers\n"
" L - Purchase lettuce\n"
" T - Purchase tomatoes\n"
" ! - Finalize bill of sale\n"
" * - Cancel this bill and reset 'for' new customer\n"
" & - Quit program\n\n"
"Enter the desired option:"
);
do
{
choice = getchar();
}
while (isspace(choice) && choice !=EOF);
choice = toupper(choice);
switch (choice)
{
total = app+cuc+let+tom;
case 'A': //APPLES
printf("Weight in kg of apples:");
scanf("%lf\n", &app);
appcost= app*3.59;
app=app+app;
break;
case 'C': //CUCUMBERS
printf("Number of cucumbers:");
scanf("%lf\n", &cuc);
cuccost= cuc*2.29;
cuc=cuc+cuc;
break;
case 'L': //LETTUCE
printf("Number of heads of lettuce:");
scanf("%lf\n", &let);
letcost= let*1.49;
let=let+let;
break;
case 'T': //TOMATOES
printf("Weight in kg of tomatoes:");
scanf("%lf\n", &tom);
tomcost= tom*1.29;
tom=tom+tom;
break;
case '!': //BILL OF SALE
if (total==0)
{
printf("No bill of sale. Nothing has been purchased.\n");
}
else
{
printf("BILL OF SALE\n"
"=============\n");
if (appcost!=0)
printf("%lf kg apples: $ %lf (TX)\n", app, appcost);
if (cuccost!=0)
printf("%lf cucombers: $ %lf (TX)\n", cuc, cuccost);
if (letcost!=0)
printf("%lf lettuce: $ %lf (TX)\n", let, letcost);
if (tomcost!=0)
printf("%lf tomato: $ %lf (TX)\n", tom, tomcost);
double sub=appcost+cuccost+letcost+tomcost;
double hst=sub*0.13;
double final=sub*1.13;
printf("\n");
printf("=============================\n");
printf(" Subtotal: $ %.2lf \n", sub);
printf(" HST: $ %.2lf \n", hst);
printf(" TOTAL: $ %.2lf \n\n", final);
printf("---------------------------------------------------------------\n");
}
break;
case '*': //CANCEL
printf("Are you sure you want to cancel the current bill (Yes/No)?");
scanf("%[^\n]", cancel);
for(counter=0; counter<strlen(cancel); counter++)
{
cancel[counter] = tolower(cancel[counter]);
/* if(cancel=='yes')
{
}
if(cancel=='no')
{
} */
}
}
if (choice=='&');
break;
}
while (1);
//while (choice!='&' && choice!=EOF);
return 0;
}
Thanks for the help in advance!!