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!!
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.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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