I don't know what is wrong with the code but for some reason the C compiler keeps getting the bools of true and false and the bool itself in several errors. I have tried to fix the problems but my solutions didn't work. It's really baffling. All solutions and comments will be taken into account. Any help is appreciated.
/*
*Standard C libraries
*/
#include <stdio.h>
#include <string.h>
/*
* Custom Headers
*/
/*
*Declaration of custom functions
*/
bool get_string();
bool get_double();
int main(int argc, char *argv[])
{
char mealChoice[100];
double total = 0.0;
double subTotal = 0.0;
double mealCost = 0.0;
const double HST = 0.15;
const double ECO_DEPOSIT = 0.10;
const char *menu =
"There is one size of hot/cold beverage: 435ml\n"
"Choices for hot beverages are: tea, cappachino, coffee\n"
"Choices for cold beverages are: orange juice, milk, chocolate milk, bottled water\n"
"Food choices for Breakfast: eggs, ham, bacon, toast with jam, and hasbrowns\n"
"Food choices for Lunch: Pizza, lasagna, mac n cheese with bacon\n"
"Food Choices for Dinner: Fish n' chips, sub with onion rings, fries, poutine, shephards pie, chicken alfredo\n"
"Prices for Breakfast: $12.50, Lunch: $15.00 and Dinner $35.00\n";
printf("%s\n", menu); // No need to call printf mutiple times.
printf("Enter the customer's choice of Meal: ");
get_string(mealChoice, sizeof mealChoice); // scanf(" %99[^\n]", mealChoice);
printf("Enter the cost of meal: \n");
get_double(&mealCost); // scanf(" %lf", &mealCost);
subTotal = mealCost + (mealCost * HST);
total = subTotal + ECO_DEPOSIT;
printf("\nYour order: %s\n", mealChoice);
printf("\nTotal cost: $%.2f\n", total);
printf("\nThank you for your support!\nCome again!\n");
return 0;
}
/*
* Custom Functions
*/
bool get_string(char *in, const size_t size)
{
if (!fgets(in, size, stdin))
{
return false; // fgets failed.
}
else
{
size_t last = strcspn(in, "\n");
in[last] = '\0';
return true;
}
}
bool get_double(double *d)
{
char in[100];
if (!get_string(in, sizeof in))
{
return false;
}
else
{
return sscanf(in, "%lf", d) == 1;
}
}