When I call a function into main function, my code gets stuck. When I debug my code, it is free of error but when I run it, it is stuck. How can I solve this?
#include <stdio.h>
float before_discount_price(int, int, char);
float discount_price(int, int, char);
void displayinfo();
int main() {
char name[20], customerID[20], type, category, memberCard;
int quantity, age;
float price, total, totalCharge;
printf("Enter Your Name: ");
gets(name);
printf("Enter Your ID: ");
scanf("%s", & customerID);
printf("Your Age: ");
scanf("%d", & age);
fflush(stdin);
printf("Choose your Activities: (A for Waterpark, B for Safari Night): ");
scanf("%c", & type);
printf("How many tickets you want to buy: ");
scanf("%d", & quantity);
fflush(stdin);
printf("Do you have a member card?: (Y for Yes, N for No):");
scanf("%c", & memberCard);
// i get stuck at here, i have no idea to solve it .....
price = before_discount_price(quantity, age, type);
total = discount_price(quantity, total, memberCard);
printf("%.2f", & total);
return 0;
}
// first function
float before_discount_price(int quantity, int age, char type) {
int total;
int i = 1;
while (i <= quantity) {
if (type == 'A') {
if (age >= 18) {
total = total + 30;
} else {
total = total + 15;
}
}
if (type == 'B') {
if (age >= 18) {
total = total + 25;
} else {
total = total + 15;
}
}
i++;
return total;
}
}
//second function
float discount_price(int quantity, int total, char memberCard) {
float totalprice, discount;
int i = 0;
while (i <= quantity && memberCard == 'Y') {
discount = total * 0.3;
}
i++;
return totalprice = total - discount;
}
//third function(not yet done)
void displayinfo() {
printf("Hi");
}
Output of Above Code:
stuck