### I need to use a for loop controlled by the number of line

Help with this C++ program?
I am supposed to create a program that outputs a table of numbers and a set of calculations performed on them. The user will enter a (type double) starting point (at least 0.0, with 1 digit after the decimal point) and an integer telling how many lines they would like the table to be. Using a for-loop (controlled by the number of lines), you are to output the
following table of values for each “n”:
n, n^2 , n^3, squareroot of n. cube root of n, ceil(n), floor (n)

Here is my code

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
double startingPoint;
int numberOflines;

cout << "Enter starting point at least 0.0, with 1 digit after the decimal point."<<endl;
cout << "Where would you like to start?" <<endl;
cin >> startingPoint;

cout << "Please enter an integer telling how many lines you would like the table to be: " <<endl;
cin >> numberOflines;

cout << fixed << showpoint << setprecision(2);
cout << "Number\tSquare\tCubed\tSquare Root\tCube Root\tCeiling\tFloor\n";
cout << "---------------------------------------…

for (double startingPoint = 0.0; startingPoint <= numberOflines; startingPoint++)
{
cout << fixed <<showpoint << setprecision(1);
cout << setw(4) << startingPoint;
cout << fixed <<showpoint << setprecision(3);
cout << "\t" << setw(4) << (startingPoint * startingPoint);
cout << fixed <<showpoint << setprecision(3);
cout << "\t" << setw(8) << (startingPoint * startingPoint * startingPoint);
cout << fixed <<showpoint << setprecision(3);
cout << "\t" << setw(12) << sqrt(static_cast<double>(startingPoint))…
cout << fixed <<showpoint << setprecision(3);
cout << "\t" << setw(16) << pow(startingPoint, 3);
cout << fixed <<showpoint << setprecision(0);
cout << "\t" << setw(20) << ceil(startingPoint);
cout << fixed <<showpoint << setprecision(0);
cout << "\t" << setw(24) << floor(startingPoint) << endl;
}

cout <<"-------------------------------------… << endl;
return 0;
}
and here is my ouput which is a complete mess
Enter starting point at least 0.0, with 1 digit after the decimal point.
Where would you like to start?
2.0
Please enter an integer telling how many lines you would like the table to be:
3
Number Square Cubed Square Root Cube Root Ceiling Floor
--------------------------------------…
0.0 0.000 0.000 0.000 0.000
0. 0.
1.0 1.000 1.000 1.000 1.000
1. 1.
2.0 4.000 8.000 1.414 8.000
2. 2.
3.0 9.000 27.000 1.732 27.000
3. 3.
--------------------------------------…

Press any key to continue . . .
and its supposed to look like this

n squared cubed square-root cube-root ceiling floor
--------------------------------------…
2.0 4.000 8.000 1.414 1.257 2 2
2.1 4.410 9.261 1.449 1.277 3 2
What am i doing wrong?
 ``12345`` ``````for(int i =0; i< number_of_lines; ++i) { point *= point; std::cout << point << std::endl; }``````

That doesn't complie at all even after declaring the variables.
ups, thought you need to read n and point and then print:
point
point^2
point^3
...
point^n

i have some probs getting your task.
i think the user should set the start and end value of a for loop, like this:

 ``1234`` ``````for(double i = starting_point; i <= number of lines; ++i) { //calculations }``````

Topic archived. No new replies allowed.