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

QUESTION

If I want the program to now print the name of the item along with the price, what must I add?

If I want the program to now print the name of the item along with the price, what must I add? I can input the number of items, and I can name the items and enter their prices and all the calculations are coming out correct on the output, I just don't know how to pull the name of the items into the printed receipt portion. I want to modify without changing my oriiginal program too much.

PS..first ever class and not getting it very well at all.

#include <iostream>

#include <string>

#include <iomanip>

using namespace std;

//begin

int main ()

{

  int numberofitems = 0; //variable to store number of items purchased

  float sum = 0.00; //sum

  float taxamount; //variable to store tax amount

  float totaltax = 0.00; // sum of total tax amount plus number of items * price of items

  float priceofitem = 0.00; //variable to store value of sales item

  char ch = 'y';

  string nameofItem;

  while (ch == 'Y' || ch == 'y')

      {

    //enter number of items and assign starting sum value of 0

    cout << "Updated program to see item name and corresponding price" <<endl << endl;

sum = 0;

    cout << "How many sales items do you have? : ";

    cin >> numberofitems;

  double EachValueofItem [numberofitems];  // Array to store sales values

    // set i to zero, it will always be less than n and will continue to be incrementally increased by 1

    // user enters the price for the first item and program keeps asking for price of items until it i = n.

     for (int i =1; i <= numberofitems; i++) {

 //enter items name using a string

        cout << "Enter in the name of sales item number " << (i) << " : ";

      cin >> nameofItem;

        cout << "Enter in the price of item " <<( i ) <<" : $";

        cin >> priceofitem;

        // accumulates sum as items are added and new prices are added

     EachValueofItem[i-1]= priceofitem;

    sum= sum+priceofitem;

  }

//enter tax percentage

  cout << "nnEnter in the sales tax percentagen";

  cout << "<Enter 10 for 10%>: ";

  cin >> taxamount;

  //calculate total sum x the tax percent and divide by 100 to state tax input number as percentage

  totaltax = (sum * taxamount) / 100;

  cout << fixed;

  cout <<setprecision (2);

  //set decimal and number of spaces after decimal point

 //display receipt--I added a line to pull the item number and its associated amount from the array so each individual item and amount stores and prints.

cout << "nn*****************************************************" << endl;

cout << "************* S A L E S R E C E I P T **************" << endl;

cout << "*****************************************************" << endl;

cout << "**                         **" << endl;

cout << "**                         **" << endl;

cout << "**                         **" << endl;

for(int i=0; i!=numberofitems; i++)

  {

     cout << "**" << "Sales itemt" << i+1 << "t$" << setw(8) << fixed << setprecision(2) << EachValueofItem[i] << "tt  **" << endl;

  }

cout << "*****************************************************" << endl;

cout << "*****************************************************" << endl;

cout << "**" << " Total Salestt$" << setw(8) << right << setprecision(2) << sum << "tt  **" << endl;

cout << "**" << " Sales taxtt$" << setw(8) << right << setprecision(2) << totaltax << "tt  **" << endl;

cout << "**" << " ttt ---------tt  **" << endl;

cout << "**" << " Grand Totaltt$" << setw(8) << right << setprecision(2) << sum + totaltax << "tt  **" << endl;

cout << "**                         **" << endl;

cout << "**                         **" << endl;

cout << "*****************************************************" << endl;

//ask if want program to run again. tried with

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