0

商品価格を無制限に入力するという私のアプローチの何が問題なのかわかりません。ただし、最大の懸念は、ゼロを押したとき (終了する必要がある方法)、入力が停止せず、最終的な出力が表示されないことです。より良いアプローチの方向性をいただければ幸いです。

#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;
}
4

2 に答える 2

1

;そのはずif(prices[i] == 0){ check = false; break; }

于 2013-02-13T01:34:22.587 に答える
1
 cout<<"Enter the price of item "<<i<<": ";
    int temp;
    cin>>temp;
if(temp == 0){

    check=false;


    break;

}

この問題を修正する必要があり、価格配列にゼロを入れません。

于 2013-02-13T01:35:01.787 に答える