By using a for loop. I want to let the user input the amount of lemonade that they want to order. Then my program will calculate the tax, subtotal, and total. After it should let them continue by either entering 'y' or 'n'.
When I compile these codes. All I get are blanks. What is wrong with my codes?
So I made some changes. But I don't know how to have it stop the program if I enter 'n' if they ask to continue.
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void main()
{
int NumCups;
float SubTot, Tot = 0, Tax;
char more;
printf("Enter the number of cups:");
scanf("%d", &NumCups);
SubTot = NumCups*1.29;
Tax = SubTot*0.0825;
Tot = SubTot + Tax;
printf("Subtotal:%0.2f\nTax:%0.2f\nTotal:%0.2f\n", SubTot, Tax, Tot);
fflush(stdin);
printf("Thank you.\nWould you like to order more lemonade?\n");
for (; scanf("%c", &more);)
{
printf("Enter the number of cups:");
scanf("%d", &NumCups);
SubTot = NumCups*1.29;
Tax = SubTot*0.0825;
Tot += SubTot + Tax;
fflush(stdin);
printf("Subtotal:%0.2f\nTax:%0.2f\nTotal:%0.2f\n", SubTot, Tax, Tot);
printf("Thank you.\nWould you like to order more lemonade?\n");
}
system("pause");
}
int main()instead ofvoid main(). Also,fflush(stdin)is undefined behaviour. (This might be related to your problem.) Also, please post a compilable example, stating the expected output and actual output explicitly.count? I don't see it used anywhere other than being incremented (for no apparent reason?). Why not just use a while loop? I think it would be more appropriate for your program.