c++

hello,i'm the new man in this programming world...and i did not know what wrong with my coding,it won't calculate and i cannot enter how much that i want to pay...i also still not good in doing the subroutine

this the question of what i must do..

write a vending machine program. Beside of allowing the customer to choose the product, your program should also display the amount charged based on the quantity of the product purchased and the balance amount that needs to be return to the customer. (You are required to use subroutines in answering this question)

this is my coding

#include <stdio.h>
#include <Windows.h>
void main_menu();//prototype
void breakfast();//prototype


void main()

{

char option=' ';
while (option!='D')
main_menu();//call function





}




void main_menu()

{
char option =' ';
int quantity=0;
int number=0;
float amount,total,balance,pay=0.0;

printf("Please select your option :\n\n");
printf("[A]Breakfast\n");
printf("[B]Lunch\n");
printf("[C]Dinner\n");
printf("[D]Exit\n");

fflush(stdin);
printf ("\nSelect you option now\n :");
scanf ("%c", &option);
system("cls");

option = toupper(option);

if (option=='A'||option=='B'||option=='C'||option=='D')


if (option=='A')
while (number!=5)
{


printf("\n\nSelect your food \n\n");
printf("[1]Roti Canai\t\trm1.00\n");
printf("[2]Nasi Lemak\t\trm1.50\n");
printf("[3]Teh Tarik\t\trm1.20\n");
printf("[4]Calculate\n");
printf("[5]Quit Main Menu \n");




fflush(stdin);
printf ("\nSelect your option now by entering respective number\n\n : ");
scanf ("%d", &number);
system("cls");
float total = 0.0;


if (number==1)



{
printf("Roti Canai\t\t rm1.00\n");
printf("Enter the quantity:\n");
scanf("%d",&quantity);
system("cls");



amount= quantity * 1.00;
total = total+amount;

printf("You have to pay :%.2f\n\n", amount);


}

if (number==2)

{
printf("Nasi Lemak\t\trm1.50\n");
printf("Enter the quantity:\n");
scanf("%d",&quantity);
system("cls");


amount= quantity * 1.50;
total=total+amount;

printf("You have to pay :%.2f\n\n", amount);

}

if (number==3)

{
printf("Teh Tarik\t\trm1.20\n");
printf("Enter the quantity:\n");
scanf("%d",&quantity);
system("cls");


amount= quantity * 1.20;
total=total+amount;

printf("You have to pay :%.2f\n\n", amount);
}


if(number==4)

{

total=total+amount;
printf("total=%.2f\n\n", total);
printf("How much you want pay\n");
scanf("%f", &pay);

while (pay >= total)

balance = pay-total;
printf("your balance is %.2f",balance);




}


if(number>5 || number<=0)

{

printf("Invalid Choice,Enter again\n");

}








}






}




void breakfast()

{


}
First, use [ code ] [ /code ] tags. You can find them on the Format section, highlight your code and press the <> button.

Also, you do realise that this is a C program, not a C++ program? Also, use int main() rather than void main(), avoid using system() calls.

Anyway, in your main function, the option character will never change, so you have an infinite loop there. Also, fflush(stdin) can sometimes produce some wierd problems, so you should probably try to avoid using it (you don't really need it). Other problems we might be able to see if you put your code in "code tags" and format it properly.
Topic archived. No new replies allowed.