I'm not sure if I'm not comparing the strings properly or not, but for some reason my toppingCost function will only return 0 or a huge wacky number (when I mess around with the code a bit). Does anyone see anything wrong with this?
// represent the cost of pizza, in pennies
#define NICKS_PIZZA 1000
#define RAYS_PIZZA 1500
#define MIKES_PIZZA 2000
// pizza eaters count
#define TAMMY_AND_SUE 2
#define TAMMY_SUE_MARY 3
#define TAMMY_SUE_MARY_CHRIS_TOM TAMMY_SUE_MARY + 2
// string constants for customers
const char *TammySue = "Tammy and Sue";
const char *TammySueMary = "Tammy, Sue and Mary";
const char *TammySueMaryChrisTom = "Tammy, Sue, Mary, Chris and Tom";
// pizza type indicator
#define PIZZA_PLAIN 0
#define PIZZA_PEPPERONI 1
#define PIZZA_SAUSAGE_ONION 2
// pizza cost of add-ons, and taxes
#define NICKS_PEPPERONI 100
#define RAYS_PEPPERONI 100
#define MIKES_PEPPERONI 150
#define NICKS_SAUSAGE_ONION 100
#define RAYS_SAUSAGE_ONION 125
#define MIKES_SAUSAGE_ONION 150
#define NYC_TAX_RATE 0.0825
// string constants for pizza dining establishments
const char *nicks_restaurant = "Nick's Pizza";
const char *rays_restaurant = "Ray's Pizza and Subs";
const char *mikes_restaurant = "Mike's Pizza and Deli Station";
//string constants for nicks, rays, mikes
const char *nicks = "nicks";
const char *rays = "rays";
const char *mikes = "mikes";
//string constants for pizza types
const char *Plain = "plain";
const char *Pepperoni = "pepperoni";
const char *SausageAndOnion = "sausage and onion";
//function prototypes
char* allLower(char*);
int toppingCost(char*, char*);
//change string to all lowercase
char* allLower(char* name)
{
int i = 0;
while(name[i] != '\0')
{
name[i] = tolower(name[i]);
++i;
}
//return string in lowercase
return name;
}
//determine the topping cost
int toppingCost(char* pizza, char* location){
int cost;
//set topping cost to 0 for plain pizza
if(strcmp(pizza, Plain)){
cost = 0;
}
//set topping cost for pepperoni pizza
else if(strcmp(pizza, Pepperoni)){
if((strcmp(location, nicks)) || (strcmp(location, rays))){
cost = 100;
}
else if(strcmp(location, mikes)){
cost = 150;
}
else{
puts("Error determining pepperoni cost.\n");
}
}
//set topping cost for sausage and onion pizza
else if(strcmp(pizza, SausageAndOnion)){
if(strcmp(location, nicks)){
cost = 100;
}
else if(strcmp(location, rays)){
cost = 125;
}
else if(strcmp(location, mikes)){
cost = 150;
}
else{
puts("Error determining sausage and onion cost.\n");
}
}
//catch errors
else{
puts("An error occured while determining the pizza type.");
}
//return cost
return cost;
}
int main(){
char tempstring[20];
char tempchar;
char *pizza_establishment;
int number_of_pizza_eaters;
char *pizza_type;
puts("Which pizza place did you visit today? \nNicks, Rays, or Mikes?");
fgets(tempstring,20,stdin);
pizza_establishment = allLower(tempstring);
//printf("%s", pizza_establishment);
while((pizza_establishment == nicks) || (pizza_establishment == rays) || (pizza_establishment == mikes)){
printf("Error while entering restaurant name. Make sure you entered the name correctly.");
printf("Which pizza place did you visit today? \nNicks, Rays, or Mikes?");
fgets(tempstring,20,stdin);
pizza_establishment = allLower(tempstring);
}
printf("\nIncluding yourself, how many people?");
//fgets(tempchar,10,stdin);
//number_of_pizza_eaters = atoi(tempchar);
scanf("%d", &number_of_pizza_eaters);
getchar();
while((number_of_pizza_eaters < 1) || (number_of_pizza_eaters == 4) || (number_of_pizza_eaters > 5)){
if(number_of_pizza_eaters == 0){
puts("Who do you think's going to eat this pizza?");
}
else{
puts("Bringing along some unexpected guests today?");
}
printf("\nIncluding yourself, how many people?");
scanf("%d", &number_of_pizza_eaters);
}
//printf("%s %d\n\n", pizza_establishment, number_of_pizza_eaters);
puts("\nWhat type of pizza will you be eating today? Plain, Pepperoni, or Sausage and Onion?");
fgets(tempstring,20,stdin);
//printf("%s", tempstring);
pizza_type = allLower(tempstring);
while((pizza_type == "plain") || (pizza_type == "pepperoni") || (pizza_type == "sausage and onion")){
puts("Incorrect Pizza Type Entered");
printf("\nWhat type of pizza will you be eating today? Plain, Pepperoni, or Sausage and Onion?");
fgets(tempstring,20,stdin);
pizza_type = allLower(tempstring);
}
//printf("%s %d\n\n", pizza_establishment, number_of_pizza_eaters);
double price;
char customers[50];
strcpy (customers,TammySue);
if(strcmp(pizza_establishment, nicks)){
price = NICKS_PIZZA;
printf("%s had lunch today at %s.\n",customers, nicks_restaurant);
}
else if(strcmp(pizza_establishment, rays)){
price = RAYS_PIZZA;
printf("%s had lunch today at %s.\n",customers, nicks_restaurant);
}
else if(strcmp(pizza_establishment, mikes)){
price = MIKES_PIZZA;
printf("%s had lunch today at %s.\n",customers, nicks_restaurant);
}
else{
puts("An error occured while determining which restaurant was visited.");
}
printf("%s", pizza_type);
//assign topping cost to toppings
int toppings = toppingCost(pizza_type, pizza_establishment);
printf("\n\n%d\n\n", toppings);
/*
Tammy had lunch today at Nick's Pizza with Sue and Mary.
They had a plain pizza today.
Total for the pizza, with tax, is $10.83.
Each of the 3 people owe $3.61 for the pizza.
Tammy had lunch today at Mike's Pizza with Sue.
They had a pepperoni pizza today, adding $1.50 extra cost.
Total for the pizza, with tax, is $23.27.
Each of the 2 people owe $11.63 for the pizza.
costINcents / 100 = $dollars.change
*/
return( EXIT_SUCCESS );
}