I would like the output of the following program to show the first integer without decimals and the rest will have 4 places..the way it is written now all outputs show as 1.0000 (or something similar)
code is as follows
//Square root and cube root calculator
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double topnum;
int loopcounter = 0;
double prod;
double root1;
double root2;
cout <<fixed<<setprecision(4)<<showpoint; //show decimal to 2 places
//User input
cout <<"This program will output a table showing the squareroot and cuberoot"<<endl;
cout <<"up to the positive integer you give. "<<endl;
cout <<endl;
cout <<"Input an integer (0 or negative number will end program) ";
cin >> topnum;
cout <<setw(6)<<"Number"<<setw(20)<<"Square Root"<<setw(20)<<"Cube Root"<<endl;
while ( topnum > 0 ) //Ends progeam if negative number or 0 is entered is entered
{
loopcounter = 0;
while ( loopcounter < topnum ) //stops loop at user input integer
{
prod = loopcounter + 1;
root1 = sqrt ( prod );
root2 = pow ( abs ( prod ), 1.0 / 3.0 );
cout <<setw(4)<<setprecision(4)<<prod<<setw(17)<<root1<<setw(20)<<root2;
cout <<endl;
loopcounter ++;
}
cout <<"Input an integer (0 or negative number will end program) ";
cin >> topnum;
}
system ("pause");
return 0;
}
so basically instead of
Number Square Root Cube Root
1.0000 1.0000 1.0000
I would like only the number column to be a single digit