I'm not that familiar to C but its the required language so I apologize for the messy code.
So basically I made a program where you can choose multiple items using a function containing a switch statement in it, then it prompts you back to said function if you wanted to order more.
I used an if else statement to calculate if the payment is enough or not. That's where the problem is. Even if I input a value higher than the total price, it still treats it as if the inputted value is not enough. I need to calculate the VAT as well but i can't make a variable for it as the totalPayment variable is not constant.
#include <stdio.h>
double asadoS=40;
double asadoL=55;
double bolaBolaS=40;
double totalPrice;
double cash;
double change;
int choice;
int choice2;
void func()
{
scanf("%d",&choice);
switch(choice){
case 1:
totalPrice=totalPrice+asadoS;
break;
case 2:
totalPrice=totalPrice+asadoL;
break;
case 3:
totalPrice=totalPrice+bolaBolaS;
break;
default:
printf("Option not available");
break;
}
prompt();
}
void prompt()
{
printf("Would you like to order more?");
printf("1.YES,2.NO");
scanf("%d",&choice2);
if(choice2==1){
func();
}
else if(choice2==2){
printf("Your total is: %f",totalPrice);
}
else{
printf("invalid input!");
}
}
main()
{
printf("Welcome to 8/11");
printf("\nEnter the corresponding number of the items you choose");
printf("\nSiopao: \n 1.Asado(small)= 40php 2.Asado(Large) = 55php \n
3.Bola-bola(s)");
func();
prompt();
printf("Please enter your payment");
printf("%f",totalPrice);
scanf("%f",&cash);
if(cash>=(totalPrice)){
printf("Your change is %f",(cash-totalPrice));
}
else if(cash<(totalPrice)){
printf("Insufficient funds. Please try again");}
else{
printf("a");
}
}