Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

?
Lv 4

Help with C++ program?

The program should do the following:

1. Display the items and prices of the 10 items.

2. Ask the user to enter the 1st item, display its price.

3. Ask the user to enter the 2nd item, display its price.

4. When they are finished entering the items, display a list of items.

5. Calculate the subtotal, add up the prices.

6. Display the subtotal

7. Calculate the tax and display it.

8.Calculate the total and display it.

9. Display a thank you and come again.

Here's what I have so far. The real problem for me is changing the ints into the price. (Xbox360 = 1 into 299.99 = 1)

// Part 2

int num1, num2;

int Xbox360 = 1;

int PS2 = 2;

int PS3 = 3;

int PS4 = 4;

int WiiU = 5;

int Xbox360Controller = 6;

int PS2Controller = 7;

int PS3Controller = 8;

int PS4Controller = 9;

int WiiUController = 10;

cout << "Welcome to Electricy Plus! " << endl;

cout << "There are ten products to choose from. " << endl;

cout << "Please choose a number between one and ten. " << endl;

cout << " " << endl;

cout << "1 = Xbox 360 Price = $299.99 " << endl;

cout << "2 = PS2 Price = $129.99 " << endl;

cout << "3 = PS3 Price = $299.99 " << endl;

cout << "4 = PS4 Price hasn't been announced yet! Pre-Order now! " << endl;

cout << "5 = Wii U Price = $299.99 " << endl;

cout << "6 = Xbox 360 Controller Price = $49.99 " << endl;

cout << "7 = PS2 Controller Price = $29.99 " << endl;

cout << "8 = PS3 Controller Price = $49.99 " << endl;

cout << "9 = PS4 Controller Price hasn't been announced yet! Pre-Order the PS4! " << endl;

cout << "10 = Wii U Controller Price = $145.00 " << endl;

cin >> num1;

if (num1 == 1)

{

cout << "You have chosen the Xbox 360. The subtotal is $299.99. " << endl;

}

if (num1 == 2)

{

cout << "You have chosen the PS2. The subtotal is $129.99. " << endl;

}

if (num1 == 3)

{

cout << "You have chosen the PS3. The subtotal is $299.99. " << endl;

}

if (num1 == 4)

{

cout << "You have chosen the PS4. This item isn't available yet! Pre-Order now!. " << endl;

}

if (num1 == 5)

{

cout << "You have chosen the Wii U. The subtotal is $299.99. " << endl;

}

if (num1 == 6)

{

cout << "You have chosen the Xbox 360 Controller. The subtotal is $49.99. " << endl;

}

if (num1 == 7)

{

cout << "You have chosen the PS2 Controller. The subtotal is $29.99. " << endl;

}

if (num1 == 8)

{

cout << "You have chosen the PS3 Controller. The subtotal is $49.99. " << endl;

}

if (num1 == 9)

{

cout << "You have chosen the PS4 Controller. This item isn't available yet! Pre-Order the PS4! " << endl;

}

if (num1 == 10)

{

cout << "You have chosen the Wii U Controller. The subtotal is $145.00. " << endl;

}

cout << "Please choose a second product. (#1-10) " << endl;

cin >> num2;

if (num2 == 1)

{

cout << "You have chosen the Xbox 360. The subtotal is $299.99. " << endl;

}

if (num2 == 2)

{

cout << "You have chosen the PS2. The subtotal is $129.99. " << endl;

}

if (num2 == 3)

{

cout << "You have chosen the PS3. The subtotal is $299.99. " << endl;

}

if (num2 == 4)

{

cout << "You have chosen the PS4. This item isn't available yet! Pre-Order now!. " << endl;

}

if (num2 == 5)

{

cout << "You have chosen the Wii U. The subtotal is $299.99. " << endl;

}

if (num2 == 6)

{

cout << "You have chosen the Xbox 360 Controller. The subtotal is $49.99. " << endl;

}

if (num2 == 7)

{

cout << "You have chosen the PS2 Controller. The subtotal is $29.99. " << endl;

}

if (num2 == 8)

{

cout << "You have chosen the PS3 Controller. The subtotal is $49.99. " << endl;

}

if (num2 == 9)

{

cout << "You have chosen the PS4 Controller. This item isn't available yet! Pre-Order the PS4! " << endl;

}

if (num2 == 10)

{

cout << "You have chosen the Wii U Controller. The subtotal is $145.00. " << endl;

}

2 Answers

Relevance
  • 8 years ago
    Favorite Answer

    Just define an array of doubles to store the prices:

    double price[10];

    price[0] = 299.99;

    price[1] = 129.99;

    ...etc...

    then access the price using num2-1.

    For example:

    if (num2 == 1)

    {

    cout << "You have chosen the Xbox 360. The subtotal is $299.99. " << endl;

    cout<<"price: "<<price[num2-1]<<endl;

    }

    You really should use a switch statement instead of all those ifs.

  • 8 years ago

    Just like modulo_function says that is the most suitable solution you could find and you can also create a variable to store the subtotal and display the total amount

    sht like:

    double fresult = 0;

    if (num1 == 1)

    {

    cout << "You have chosen the Xbox 360. The subtotal is $299.99. " << endl;

    cout<<"price: "<<price[num2-1]<<endl;

    fresult += price[num1-1];

    }

    ...

    if (num2 == 1)

    {

    cout << "You have chosen the Xbox 360. The subtotal is $299.99. " << endl;

    cout<<"price: "<<price[num2-1]<<endl;

    fresult += price[num2-1];

    }

    cout<<"Total: "<<fresult<<endl;

Still have questions? Get your answers by asking now.