GCDEF gave you the hints that you need to make your program right. Also, please format your code. Use 'Go Advanced' then select the code then press '#' It makes the code much easier to read.
When you have \n in a string this causes a new line to be started in the output. So the \n\n after x^2 causes 2 new lines to be output which is probably not what you want. You also want the output in the same order as your heading which is x sqrt(x) x^2 and x^3 but you are outputting in the order x^3 x sqrt(x) x^2. Cout outputs in the order that it is used.Code:#include "stdafx.h" #include <iostream> #include <cmath> using namespace std; int main() { double x; cout.precision(4); cout << " x sqrt(x) x^2\n\n x^3\n"; for (x = 1.0; x <= 20.0; x++) { cout.width(); cout << x*x*x << " "; cout.width(7); cout << x << " "; cout.width(7); cout << sqrt(x) << " "; cout.width(7); cout << x*x << '\n'; } system("pause"); return 0; }




Reply With Quote