我是新来编程,我试图让这个程序加起来咖啡的价格,以增加额外的东西,如肉桂等,但一旦程序运行它并没有增加额外的咖啡价格,我已经在它上面好几个小时了,我很难过。就像我说的,我是新手,所以如果有人可以帮助并解释为什么它不工作,或者我需要解决这个问题,那将会很棒。谢谢! 代码:我的c + +程序不会加起来我的总价
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
const int SIZE = 5;
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};
int 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: " ;
cout << "Product Price ($)" << endl;
cout << "======= =========" << 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 > SENTINEL)
{
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" ;
}
}
totalPrice + COFFEEPRICE;
cout << "Total price of order is $" << totalPrice << endl;
cout << "Thanks for purchasing from Jumpin Jive Coffee Shop" << endl;
}
system("pause");
return 0;
}