snaptrap013 icon

asdasd

snaptrap013 | PRO | 05/02/21 09:11:20 AM UTC | 0 ⭐ | 987 👁️ | Never ⏰ | []
C |

1.75 KB

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <string.h>
 
void Display_Menu();
float Calculate_totalPayment();
float Calculate_balance(float balance, float total);
void Display_Receipt(float total, float balance);
 
 
int main()
{
    char order = 'y';
    float balance, total;
    printf("Please enter your amount of topup: ");
    scanf("%f", &balance);
    Display_Menu();
    while (order == 'y')
    {
        total = Calculate_totalPayment();
        balance = Calculate_balance(balance, total);
        Display_Receipt(total, balance);
        printf("\nDo you want to order a new one [Y = yes | N = no]? ");
        scanf(" %c", &order);
    }
}
 
void Display_Menu()
{
    printf("\nmenu : \nNasi Goreng RM5.00\nMee Goreng RM3.00\nTeh O RM1.00\nMilo Ice RM3.00");
}
 
float Calculate_totalPayment()
{
    char food[256], drink[256];
    int foodquantity, drinkquantity;
    float foodPrice, drinkprice, total;
    printf("\n\nPlease enter your food:");
    fflush(stdin);
    gets(food);
    printf("Please enter your food quantity: ");
    scanf(" %d", &foodquantity);  
    printf("Please enter your drink:");
    fflush(stdin);
    gets(drink);
    printf("Please enter your drink quantity: ");
    scanf(" %d", &drinkquantity); 
    if(strcmp(food, "Nasi Goreng") == 0)
        foodPrice = 5;
    else
        foodPrice = 3;
    if(strcmp(drink, "Teh O") == 0)
        drinkprice = 1;
    else
        drinkprice = 2;
    total = (foodPrice * foodquantity ) + (drinkprice * drinkquantity);
    return total;
}
 
float Calculate_balance(float balance, float total)
{
    balance = balance - total;
    return balance;
}
 
void Display_Receipt(float total, float balance)
{
    printf("Total: %.2f\nBalance: %.2f", total, balance);
}

Comments