Answered You can hire a professional tutor to get the answer.

QUESTION

Good evening, this code is currently giving me an error of not allowing me to get the price for the last item being input. For example: 1st item =...

Good evening, this code is currently giving me an error of not allowing me to get the price for the last item being input. For example:

1st item = 5.00

2nd item = 3.00

I choose 1 quanity of both items

result is just the first items price.

Code attached:

// Menu Selection

#include <iostream>

#include <cmath>

using namespace std;

// Declaring all my variables

char selection = ' ';

int nailSelection;

int stapleSelection;

int penSelection;

string name = "", address = "";

double nailPrice = 5.99;

double staplePrice = 3.99;

double penPrice = 1.99;

double totalCost;

int nailQuanity;

int stapleQuanity;

int penQuanity;

double nailTotal;

double stapleTotal;

double penTotal;

int main(void)

{

 char selection = ' ';

 string name = "", address = "";

 //Ask user for her/his name

 cout << "Please enter your name ==> ";

 getline(cin, name);

 //Ask user for her/his name

 cout << "Please enter your address ==> ";

 getline(cin, address);

 //display user name

 cout << "Welcome " << name << " from " << address << " to www.BigDepot.com" << endl; 

 {

 label:

  double totalCost = (nailTotal + stapleTotal + penTotal);

  cout << "Please select from our available products below!" << endl;

// display menu

 cout << "My Menu";

 cout << "========" << endl;

 cout << "1 - Nails $" << nailPrice << endl;

 cout << "2 - Staples $" << staplePrice << endl;

 cout << "3 - Pens $" << penPrice << endl;

 cout << "X - Exit " <<endl << endl;

 cout << "Enter selection: ";

 // read user selection

 cin>>selection;   

// The switch statement and calaculation of goods.

switch(selection)

  {

  case '1':

     cout << "You have selected Nails" << endl;

     cout << "How many boxes of Nails would you like?";

  cin >> nailQuanity;

  nailTotal = nailPrice * nailQuanity;

  cout << "$" << nailTotal << endl;

  cout << "Would you like another item? 1 = Yes, 2 = No" << endl;

  cin >> nailSelection;

  if (nailSelection == 1)

  goto label;

else;

  cout << "Your total cost for your item(s) is $" << totalCost << endl;

    break;

case '2':

     cout << "You have selected Staples" << endl;

     cout << "How many boxes of Staples would you like?";

  cin >> stapleQuanity;

  stapleTotal = staplePrice * stapleQuanity;

  cout << "$" << stapleTotal << endl;

  cout << "Would you like another item? 1 = Yes, 2 = No" << endl;

  cin >> stapleSelection;

  if (stapleSelection == 1)

  goto label;

else;

  cout << "Your total cost for your item(s) is $" << totalCost << endl;

    break;

case '3':

     cout << "You have selected Pens" << endl;

     cout << "How many boxes of Pens would you like?";

  cin >> penQuanity;

  penTotal = penPrice * penQuanity;

  cout << "$" << penTotal << endl;

  cout << "Would you like another item? 1 = Yes, 2 = No" << endl;

  cin >> penSelection;

  if (penSelection == 1)

  goto label;

else;

  cout << "Your total cost for your item(s) is $" << totalCost << endl;

    break;

case 'X' :

case 'x' :

cout << "Thank you and have a good day!" + name << endl;

   break;

   default : cout << "Invalid selection, Please try again";

}

  }

return 0;

  }

  //ERROR: Not accepting last input to totalprice

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question