|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
usual suspect
Join Date: Jun 2002
Location: not here
Posts: 2,051
|
i have a 2d array, and i want to make the last column of that array be a dollar amount. i have the dollar sign there, but i can't seem to set the precision to 2 like i can with a regular variable. does anyone know how to output all of the values in the last column with a decimal point? thanks in advance.
craig
__________________
the universe is against this current wave of success i'm having. -johnny drama, entourage |
|
|
|
|
|
#2 |
|
Member (8 bit)
|
Try using the header #include
Then before the output for the dollar amount use: cout.precision(2); cout.setf(ios::fixed|ios::showpoint); You may be using the same type of thing for a variable but there is no reason you can't format the output of the array the same way. I believe you are just telling it how you want it to display. I am a newbie at this, but I just finished a problem in my homework doing this very thing. |
|
|
|
|
|
#3 |
|
Member (8 bit)
|
If it helps...here is the homework I was talking about...
//Payroll Program //Tim Devine Chapter 7 #6 #include #include void main (void) { //Declare and initialize employee number, rate,hours,wages int empId[8]={5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489}; int hours[3]; float payRate[5]; float wages[6]; //for loop for (int index=0;index<7;index++) { cout<<"Please enter the pay rate for employee "< if (payRate[index]<6) cout<<"OK Cheap Scate, how about paying more than $6.00/hr?\n"; cout<<"Please enter the hours this employee worked"<<": "; cin>>hours[index]; if (hours[index]<0) cout<<"How about using a positive number?\n"; } //Display each employee's wages cout.precision(2); cout.setf(ios::fixed|ios::showpoint); cout<<"Emplyee Number"<<" "<<"Wages"< for (int build=0;build<7;build++) { wages[6]=payRate[3]*hours[3]; cout< } Last edited by revelation; 04-21-2003 at 03:21 PM. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|