i have this program and it's working fine until the very end. When I ask the user if he/she wants to do a discount and the user enters y/n, the program just halts and doesn't go to the if statement. Any help? Thanks
#include <stdio.h>
int c;
int code;
int quantity;
double amount;
double total=0;
int i;
char ask;
double discount;
double disc;
double net;
int anykey;
double prices[7]= { 2.55, 12.07, 2.00, 0.55, 5.35, 8.65, 2.55};
int main(void)
{
menu();
}
int menu()
{
printf("1.Create a new bill\n");
printf("2.Exit\n");
scanf("%d",&c);
switch(c){
case 1: function();
break;
case 2: return 0;
break;
}
return 0;
}
int function()
{ do{
printf("Enter the code: ");
scanf("%d",&code);
if(code != -1){
printf("Enter quantity: ");
scanf("%d",&quantity);
amount= ((prices[code]) * quantity);
total= (total + amount);
//printf("%.2f\n",total); for me to check
}
} while (code !=-1);
calculate();
getchar();
return 0;
}
int calculate(){
printf("Do you want to make a discount? y/n \n");
scanf("%c",&ask);
if (ask == 'y')
{
printf("Enter the actual money that you want to make a discount\n");
scanf("%f",&disc);
discount= (total * (disc/100));
net= (total - discount);
printf("The total bill is: %.2f\n", net);
}
else
if(ask == 'n')
{
printf("The total bill is: %.2f\n", total);
}
//menu();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire