On Fri, 20 Feb 2004 00:41:57 GMT, red floyd wrote in comp.lang.c++:
1. You're using old headers.
Yes, fixed that now. :-)
2. use showpoint or fixed
I hadn't heard of those commands. The teacher was telling us to just put
cout.precision( 2) right inside of main, but that wasn't working.
3. Main returns int
Yes, I know but the teacher hasn't "shown" us that part yet. I know a
little more than the teacher is telling us because it's just a programming
logic class and I've done a little reading on my own regarding C++. I
didn't want to use stuff the teacher hasn't shown us in class.
#include <iostream>
#include <iomanip>
using namespace std;
double custname = 0;
int main()
{
custname = 12.5;
cout << setprecision(4) << showpoint << custname << endl;
cout << setprecision(4) << fixed << custname << endl;
return 0;
}
generates:
12.50
12.5000
}
I just gave this a shot and it worked good:
#include <iostream>
#include <iomanip>
using namespace std;
float custname=0;
float roomnum=0;
void main()
{
cout.setf(ios_b ase::fixed, ios_base::float field);
cout.precision( 2);
cout << custname << endl;
cout << roomnum << endl;
}
It also seems to toggle on the 2 decimal place precision which is what I
was looking for and I think the teacher meant but I don't know why he
didn't tell us about the cout.setf line. I also figured out that without
the using namespace std; line, it doesn't work either and that's also
something the teacher hasn't told us to use so again, I wasn't going to go
over what he was already showing us. However, in this case I think I'll
just use it (like I have a choice).
Thanks for the help, though. It gives me another choice to use. :-)
Dave
--
You can talk about us, but you can't talk without us!
US Army Signal Corps!!
http://www.geocities.com/davidcasey98
Remove "IH8SPAM" to reply!