Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 04-21-2003, 10:06 AM   #1
usual suspect
 
hobey19's Avatar
 
Join Date: Jun 2002
Location: not here
Posts: 2,051
Question set precision in 2d array

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
hobey19 is offline   Reply With Quote
Old 04-21-2003, 03:07 PM   #2
Member (8 bit)
 
Join Date: Aug 1999
Location: Florida
Posts: 237
Send a message via AIM to revelation
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.
revelation is offline   Reply With Quote
Old 04-21-2003, 03:09 PM   #3
Member (8 bit)
 
Join Date: Aug 1999
Location: Florida
Posts: 237
Send a message via AIM to revelation
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 "< cin>>payRate[index];
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.
revelation is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:57 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2