I'm in the middle of creating a point of sale program which simply offers two choices, one for each imaginary "course".
My main problem is that it keeps closing in on itself when I type anything other than 'b'.
I have to stress that I can't use anything more advanced than do-while or and/or functions.
Here is the code:
#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
cout << "Would you like a burger (type 'b') or hotdog (type 'hd')?"; //User chooses entree
cin >> entree; //User enters option: Here's where the problems begin
if (entree == 'b') {
cout << "Added price: " << burger; //Explains current price
}
elseif (entree == 'hd') {
cout << "Added price: " << hotdog; //Explains current price
}
else {
cout << "Sorry, I didn't catch that. Please enter 'b' or 'hd'.";
}
cout << "Would you like French fries (type 'ff') or onion rings (type 'or')?"; // To sides
cin >> side;
if (side == 'ff') {
cout << "You chose French fries!";
cout << "Added price: " << fries;
}
elseif (side == 'or') { // Now to onion rings
cout << "You chose onion rings!";
cout << "Added price: " << rings;
}
else{
cout << "Sorry, I didn't catch that. Please enter 'ff' or 'or'.";
}
cout << "Would you like a soda (type 's') or a milkshake? (type 'm')?"; // Beverage
cin >> beverage;
if (beverage == 's') {
cout << "You chose a soda!";
cout << "Added price: " << soda;
}
elseif (beverage == 'm') { // If
cout << "You chose a milkshake!";
cout << "Added price: " << shake;
}
else {
cout << "Sorry, I didn't catch that. Please enter 's' or 'm'.";
}
}
cout << "Please press a key and <enter> to exit: ";
cin >> exit;
return 0;
}
Notice that I haven't started on a receipt yet. I will also need guidance when it comes to that.
I had also considered using nested if-else statements, which I will post at a later time.