我不确定输入无限数量的商品价格的方式有什么问题。但是,最大的问题是当我按零(它需要以何种方式终止)时,输入不会停止并且最终输出也不会显示。更好的方法的任何方向将不胜感激。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int MAX=8;
bool check=true;
double totalPrice, discount, discountedPrice;
double *prices = new double[];
cout<<"Enter the price of your items.";
cout<<"Enter zero (0) when you have finished entering all the items.\n\n";
while(check==true)
{
for(int i=0;i<MAX;i++)
{
cout<<"Enter the price of item "<<i<<": ";
cin>>prices[i];
if(cin==0){
check=false;
break;
}
}
if(prices==0)
{
check=false;
break;
for(int j=0; j<sizeof(prices);j++)
{
totalPrice+=prices[j];
}
discount=totalPrice*.075;
discountedPrice=totalPrice-discount;
cout<<"The total price of your "<<sizeof(prices)<<"items is: $"<<totalPrice;
cout<<"Discount of your "<<sizeof(prices)<<"is: $"<<discount;
cout<<"\nThe discounted price of your "<<sizeof(prices)<<"is: $"<<discountedPrice;
}
}
cin.get();
cin.get();
return 0;
}
最佳答案
;应为if(prices[i] == 0){ check = false; break; }