info: the majority of my problem is solved so far. please scroll to the very bottom to "here is my progress so far" to help me further, if you want to. thanks!
i have the following code and i would like to display the compiled results of this code in a clean table-like order to make it more clear for the users looking at the compiled command line program.
#include <iostream> #include <cmath> using namespace std; int main() {double x; for(x=-10;x<=10;x+=0.5) cout << "x=" << x << 3*x*x-7*x+5 << endl; return 0; }
i was a little bit in a hurry so i couldnt really see what the teacher wrote on the board how to add a table-like ordering to it. i only remember something like this:
#include <iostream> #include <cmath> using namespace std; int main() {double x; for(x=-10;x<=10;x+=0.5) cout << "x=" << x << "|*|" << 3*x*x-7*x+5 << endl; return 0; }
i know the 2nd code is probably totally wrong, but it was a code with this symbol: |
does that make any sense for someone? maybe someone can figure out what exactly my teacher tried. or maybe there is another way to display the values in a good and clear order.
let me give you an example what i exactly mean by clear order. the following example will show you compiled results (in cmd) of the first code (chaotic, no order etc)
x=-10 375 x=-9.5 465 x=-9 123 x=-8.5 124
instead of the result above, i would like to have something like..
x= - 10.0 375 x= - 9.5 465 x= - 9 123 x= - 8.5 124
unfortunately i dont know how to do that. i looked up some methods, but i was thinking: maybe what my teacher tried to show is easier than the methods i looked up. so maybe someone here knows how it is done the way i tried to do in the 2nd code. if not, i would be glad if someone could tell me the shortest and easiest way to sort the output.
thanks in advance
.---------------------------------- .
here is my progress so far. i used setw to add width to the lines. the changed code would look like this (with include iomanip added):
cout << std::setw(10) << x << std::setw(10) << 3*x*x-7*x+5 << endl;
problem is, the number ranges dont fit. like.. the single digits, ten-step digits, hundred-step digit are not in the same row. they kind of look like this:
-10.0 375
-9.5 342.25
etc..
i would like the make the result into something like this, you can clearly see the first digit, 2nd digit etc... of the numbers:
- 10.0 375
- 9.5 342.25
someone maybe knows how i give the command to order it like that?