Reference no: EM13161437
Write a program that displays columns titled "Name", "Quantity", "Price", and "Value". The fourth column contains the result of multiplying each item's quantity by its price. In addition, the program should calculate and display the total value of the items in inventory. Display the price, value, and total value with two decimal places. Save and the run the program
I began with the following cpp, but I am experiencing difficulty in getting my columns to align.
Here is the cpp:
#include <iostream>
using namespace std;
int main(){
string caName[5] = {};
int iaQuantity[5] = {};
double iaPrice[5] = {};
double iaValue[5] = {};
for (int x = 0; x<5; ++x)
{
cout << "Enter an item: ";
cin >> caName[x];
}
cout << endl;
for (int x = 0; x<5; ++x)
{
cout << "Enter " << caName[x] << "'s quantity: ";
cin >> iaQuantity[x];
}
cout << endl;
for (int x = 0; x<5; ++x)
{
cout << "Enter " << caName[x] << "'s price: ";
cin >> iaPrice[x];
}
cout << endl;
for (int x = 0; x<5; ++x)
{
iaValue[x] = iaQuantity[x]*iaPrice[x];
}
cout<< endl;
cout << "Name""\t""\t""Quantity""\t""Price""\t""\t""Value" << endl;
cout << endl;
for (int x = 0,a = 0, p = 0; x<4, a < 5, p < 5; ++x, ++a, ++p)
{cout << caName[x] <<"\t"""#";
cout << iaQuantity[a] <<"\t""\t""$";
cout << iaPrice[a] <<"\t""\t""$";
cout << iaValue[a] <<"\t""\t"" ";
cout << "\n";
}
}
I must enter the following information to execute the program:
Watch #400 $55.54
Ring #550 $99.99
Bracelet #600 $20
Earrings #100 $10.99
Pins #10 $24.35