I really could use some help with learning C++ programming . . . I'm trying to write a program that needs to print my numbers right-justified in a column on the screen and I haven't been successful . . . PLEASE HELP!!
Printable View
I really could use some help with learning C++ programming . . . I'm trying to write a program that needs to print my numbers right-justified in a column on the screen and I haven't been successful . . . PLEASE HELP!!
Show us what code you have so far, and then we'll be able to do more for ya.
I've tried posting the code, however, I keep getting an error message telling me to post the code tags and I guess I'm not inserting them in the right places.
Here it is:
Code:#include <iostream>
#include <iomanip>
using namespace std;
const int INT_NUMBER = 1066;
intValue_1 = 1066;
intValue_2 = 1492;
intValue_3 = 512;
intValue_4 = 1;
intValue_5 = -23;
int main()
{
cout << fixed << showpoint;
cout << setw(5) << intValue_1
<< setw(5) << intValue_2
<< setw(4) << intValue_3
<< setw(2) << intValue_4
<< setw(4) << intValue_5;
return 0;
}
to force right justified you can do this:
cout.setf(ios::right);
but I think right justification is the default. To use multiple ios flags you can do something like this, I think;
cout.setf(ios::fixed | ios::showpoint | ios::right);
To create a column 10 char wide with decimal representation to precision of 3, right justified you could try this:
not compiled so not sure everything works as intended. You can play around with it and look up ios manipulators and ios flags in your favorite resource to try to get it all set up.Code:float num[3];
num[0] = 3.14159;
num[1] = 123.4
num[2] = 9999.9999999999999999999999999;
int i;
for(i = 0; i < 3; ++i)
{
cout.setw(10);
cout.setprecision(3);
cout.setf(ios::fixed | ios::showpoint | ios::right);
cout << num << endl;
}
and hopefully output will be
3.141
123.400
9999.999