0

I'm not sure what's wrong with my approach to inputting an unlimited amount of item prices. However, the biggest concern is when I press zero (the way it needs to terminate with), the inputting does not halt and the final outputs are not displayed. Any direction in a better approach would be appreciated.

#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;
}
5
  • 2
    Use a vector for something that resizes itself for you. Commented Feb 13, 2013 at 1:26
  • The array seems to be fine, I checked that. However, I can't get the input of zero to terminate the loop. I want it to be as simple as possible please. Commented Feb 13, 2013 at 1:27
  • Well, double *prices = new double[]; isn't even valid syntax. Commented Feb 13, 2013 at 1:32
  • What do you suggest? This array needs to handle decimal values and it has worked so far. Commented Feb 13, 2013 at 1:34
  • I already suggested std::vector. I don't know if this is an MSVC extension, but a vector does that just fine with push_back or whatever insertion method you prefer. Commented Feb 13, 2013 at 1:36

2 Answers 2

1

;It should be if(prices[i] == 0){ check = false; break; }

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, after messing around with it, your logic worked good.
1
 cout<<"Enter the price of item "<<i<<": ";
    int temp;
    cin>>temp;
if(temp == 0){

    check=false;


    break;

}

Should fix this issue, and it won't put a zero in the prices array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.