English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

A certain product is to sell for unitPrice Dollars.Write a program that reads value for unitPrice and totalNumber and then produces a table showing the total price of from 1 through totalNumber units. The table formating is as follows.

Number of Units ///// Total Price
1--- $1.50
2---- $3.00
3---- $4.50
4--- $6.00
5--- $7.50

I have the program written out to a certain extent but I can't get the neccessary output that it is calling for in the table like formatting.

2007-02-08 04:17:46 · 3 answers · asked by gatz1000 4 in Computers & Internet Programming & Design

3 answers

You will need to use a combination of setw and setprecision manipulators in order to format your output as required.

For more details and examples on each, see this link: http://www.fredosaurus.com/notes-cpp/io/omanipulators.html


Thanks.

2007-02-08 07:16:12 · answer #1 · answered by Fox 3 · 2 0

#include
using namespace std;

int main() {
float unitPrice=1.50;
int i,n;
float a[50];
float sum;

while (true){
system("cls");
cout << "\n\nAt most how many item : ";
cin >> n;

sum=0;
cout << "\n\nItem" << "\tPrice" << endl;

for (i=1;i<=n;i++){
a[i]=i*unitPrice;
sum=sum+a[i];
cout << i << "\t" << "$" << a[i] << endl;
}
cout << endl << endl;
cout << "Total price : $" << sum;
cout << endl << endl;
system("pause");
}
}

2007-02-08 04:37:42 · answer #2 · answered by iyiogrenci 6 · 2 0

I think you'll need to use the "setw()" function.

I don't remember any more, unfortunately :-(

2007-02-08 04:24:02 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers