This program works just fine when I enter "b" as "entree", but it loops back to the opening statement when I enter "hd". When I enter "ff" after I've typed "b", however, it also closes. Can someone help me here?
The variable, entree, is a char, meaning it can only hold a single character, whereas, your typing two in some instances. Same with side. It also can only hold one character.
#include <iostream>
usingnamespace std;
int main() {
char exit;
char entree;
double burger = 3.50; // Cost of burger equals $3.50
double hotdog = 2.50; // Cost of hot dog equals $2.50
char side;
double fries = 1.50; // Cost of French fries equals $1.50
double rings = 2.00; // Cost of onion rings equals $2.00
char beverage;
double soda = 1.00; // Cost of soda equals $1.00
double shake = 3.25; // Cost of shake equals $3.25
double tax = 1.0825; // Tax in Woodland, California
double subtotal = 0; // Subtotal
double display;
do {
cout << "Would you like a burger (type 'b') or hotdog (type 'h')?";
cin >> entree;
if (entree == 'b') {
cout << "Current subtotal: " << subtotal + burger << endl; //Explains current price
cout << "Would you like French fries (type 'f') or onion rings (type 'r')?"; //Sides
cin >> side;
if (side == 'f') {
display = subtotal + burger + fries;
cout << "Current subtotal: " <<display << endl; //Explains current price
cout << "Would you like a soda (type 's') or a milkshake? (type 'm')?"; // Beverage
cin >> beverage;
if (beverage == 's') {
display = subtotal + burger + fries + soda;
cout << "Current subtotal: " <<display << endl;
cout << "Thanks for visiting!";
}
elseif (beverage == 'm') {
display = subtotal + burger + fries + shake;
cout << "Current subtotal: " << display << endl;
cout << "Thanks for visiting!";
}
else {
cout << "Sorry, I didn't catch that. Please enter 'soda' or 'milk'.";
}
}
elseif (side == 'r') {
display = subtotal + burger + rings;
cout << "Current subtotal: " <<display << endl;
cout << "Would you like a soda (type 's') or a milkshake? (type 'm')?";
cin >> beverage;
if (beverage == 's') {
display = subtotal + burger + soda + rings;
cout << "Current subtotal: " <<display << endl;
cout << "Thanks for visiting!";
}
elseif (beverage == 'm') {
display = subtotal + burger + shake + rings;
cout << "Current subtotal: " <<display << endl;
cout << "Thanks for visiting!";
}
else {
cout << "Sorry, I didn't catch that. Please enter 'soda' or 'milk'.";
}
}
else {
cout << "Sorry, I didn't catch that. Please enter 'f' or 'r'. \n\n";
}
}
elseif (entree == 'h') {
cout << "Current subtotal: " << subtotal + hotdog; //Explains current price
cout << "Would you like French fries (type 'f') or onion rings (type 'r')?"; //Sides
cin >> side;
if (side == 'f') {
cout << "Current subtotal: " << subtotal + hotdog + fries; //Explains current price
cout << "Would you like a soda (type 's') or a milkshake? (type 'm')?";
cin >> beverage;
if (beverage == 's') {
cout << "Current subtotal: " << subtotal + hotdog + soda + fries;
cout << "Thanks for visiting!";
}
elseif (beverage == 'm') {
cout << "Current subtotal: " << subtotal + hotdog + shake + fries;
cout << "Thanks for visiting!";
}
else {
cout << "Sorry, I didn't catch that. Please enter 'soda' or 'milk'.\n\n";
}
}
elseif (side == 'r') {
cout << "Current subtotal: " << subtotal + hotdog + rings;
cout << "Would you like a soda (type 's') or a milkshake? (type 'm')?";
cin >> beverage;
if (beverage == 's') {
cout << "Current subtotal: " << subtotal + hotdog + soda + rings;
cout << "Thanks for visiting!";
}
elseif (beverage == 'm') {
cout << "Current subtotal: " << subtotal + hotdog + shake + rings;
cout << "Thanks for visiting!";
}
else {
cout << "Sorry, I didn't catch that. Please enter 's' or 'm'. \n\n";
}
}
else {
cout << "Sorry, I didn't catch that. Please enter 'f' or 'r'.\n\n";
}
}
else {
cout << "Sorry, I didn't catch that. Please enter 'b' or 'h'.";
}
} while (entree != 'b' || entree != 'h' || side != 'f' || side != 'r' || beverage != 's' || beverage != 'm');
cout << "Please press a key and <enter> to exit: ";
cin >> exit;
return 0;
}
I already resolved the creation of receipt issues (I don't have a copy of the program with me right now). All I need to do is resolve issues surrounding do-while loops. Can anyone pinpoint the way?