Hey guys I have to make a program to print squares and square roots of all numbers from 1-81 using functions only. Each line I have to print the number, it's square, and its square root.
#include <iostream>
#include <cmath>
#include <iomanip>
usingnamespace std;
double squarerootchart() { //my function to call upon when i need this table displayed
double x = 0;
for (double x = 1; x < 82; x++)
{
double y = x;
double z = sqrt(x);
double a = pow(x, 2);
cout << y << std::setw(20) << z << std::setw(20) << a << endl;
}
return x;
}
int main() { //main function that calls upon squarerootchart
cout << "These are all the square and square roots of numbers 1-81:" << endl;
cout << " " << endl;
cout << "Integer" << std::setw(18) << "Square Root" << std::setw(18)<< "Square" << endl;
squarerootchart();
}
How can I simplify this even further? I am confused on what steps to take next so I don't need the for loop in my squarerootchart function.