Oct 3, 2018 at 12:20am UTC
Not completely sure but I think you just need some curly brackets around the statements.
edit: You need a && instead of the 'and'
1 2 3 4 5 6 7 8 9 10 11 12 13
if (choice != -1){
if (choice >= 1 && choice <= 5)
{
totalPrice = totalPrice + prices[choice - 1];
cout << "Item number" << choice << ":" << products[choice - 1] << "has been added" << endl;
}
else
{
cout << "Item number" << choice << "is not valid" << "Sorry we do not carry that item" << endl;
}
}
Last edited on Oct 3, 2018 at 12:24am UTC
Oct 3, 2018 at 12:31pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
const int SIZE = 5;
const double COFFEEPRICE = 2.00;
string products [SIZE] = {"Whipped cream" , "Cinnamon" , "Chocolate sauce" , "Amaretto" , "Irish whiskey" };
double prices[SIZE] = {0.89, 0.25, 0.59, 1.50, 1.75};
double totalPrice = 0;
int choice = 0;
int SENTINEL = -1;
while (choice != SENTINEL)
{
cout << "Please select an item from the Product menu by selecting the item number (1 - 5) or -1 to terminate: " << endl;
cout << "Product Price ($)" << endl;
cout << "1. Whipped cream 0.89" << endl;
cout << "2. Cinnamon 0.25" << endl;
cout << "3. Chocolate sauce 0.89" << endl;
cout << "4. Amaretto 1.50" << endl;
cout << "5. Irish whiskey 1.75" << endl;
cout << "Please enter a positive number" << endl;
cin >> choice;
if ((choice >= 1) && (choice <= 5))
{
totalPrice = totalPrice + prices[choice - 1];
cout << "Item number" << choice << ":" << products[choice - 1] << "has been added" << endl;
}
else if (choice != -1)
{
cout << "Item number" << choice << "is not valid" << "Sorry we do not carry that item" << endl;
}
}
totalPrice = totalPrice + COFFEEPRICE;
cout << "Total price of your order is " << totalPrice << endl;
cout << "Thanks for purchasing from Jumpin Jive Coffee Shop" << endl;
system ("PAUSE" );
return 0;
}
good catch mbozzi I missed that.
Last edited on Oct 3, 2018 at 3:24pm UTC