#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;
int main()
{
int qty1;
cout << "Please enter the quantity of Televisions: "<<endl;
cin >> qty1;
int qty2;
cout << "Please enter the quantity of Video Recorder: "<<endl;
cin >> qty2;
int qty3;
cout << "Please enter the quantity of Camera: "<<endl;
cin >> qty3;
int qty4;
cout << "Please enter the quantity of DVD: "<<endl;
cin >> qty4;
int qty5;
cout << "Please enter the quantity of HiFi Stereo: "<<endl;
cin >> qty5;
int qty6;
cout << "Please enter the quantity of Video CD: " <<endl;
cin >> qty6;
int price1;
cout << "Please enter the price of Televisions: "<<endl;
cin >> price1;
int price2;
cout << "Please enter the price of Video Recorder: "<<endl;
cin >> price2;
int price3;
cout << "Please enter the price of Camera: "<<endl;
cin >> price3;
int price4;
cout << "Please enter the price of DVD: "<<endl;
cin >> price4;
int price5;
cout << "Please enter the price of HiFi Stereo: "<<endl;
cin >> price5;
int price6;
cout << "Please enter the price of Video CD: " <<endl;
cin >> price6;
float totalStockValue1 = qty1 * price1; //the equation that calculates the price of the item multipled by the quantity
float totalStockValue2 = qty2 * price2;
float totalStockValue3 = qty3 * price3;
float totalStockValue4 = qty4 * price4;
float totalStockValue5 = qty5 * price5;
float totalStockValue6 = qty6 * price6;
float totalGrossValue = totalStockValue1 + totalStockValue2 + totalStockValue3 + totalStockValue4 + totalStockValue5 + totalStockValue6; //calculates the total value of all the inputs
cout<<setiosflags(ios::fixed)<<setprecision(2); //sets the output to 2 decimal places
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<setw(15)<< "Item" //fomats the output
<<setw(11)<< "Quantity"
<<setw(13)<< "Unit Price"
<<setw(14)<< "Total Value"<<endl;
cout<<"============================================================="<<endl;
cout<<setw(15)<< "Television"
<<setw(11)<< qty1
<<setw(13)<< price1
<<setw(14)<< totalStockValue1<<endl;
cout<<setw(15)<< "Video Recorder"
<<setw(11)<< qty2
<<setw(13)<< price2
<<setw(14)<< totalStockValue2<<endl;
cout<<setw(15)<< "Camera"
<<setw(11)<< qty3
<<setw(13)<< price3
<<setw(14)<< totalStockValue3<<endl;
cout<<setw(15)<< "DVD"
<<setw(11)<< qty4
<<setw(13)<< price4
<<setw(14)<< totalStockValue4<<endl;
cout<<setw(15)<< "HiFi Stereo"
<<setw(11)<< qty5
<<setw(13)<< price5
<<setw(14)<< totalStockValue5<<endl;
cout<<setw(15)<< "Video CD"
<<setw(11)<< qty6
<<setw(13)<< price6
<<setw(14)<< totalStockValue6<<endl;
cout<<"============================================================="<<endl;
cout<<setw(45)<< "Gross Total: "
<<setw(4)<<gross<<totalGrossValue<<endl;
system("pause");
}
i have this code here which when the client enters the quantity and the price for each item. i know the code is excessive but this is the only way i know i could make it work. can someone tell me how i change it to arrays and for or while loops?