This article show you how to use for loop iteration statement in C++ and the use of functions I called this program Square and Cube Root in C++. That will ask the user to enter a number and then it will generate the square and cube root value of the given number.
If you have some questions about programming, about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. People here in the Philippines can contact me at my mobile number 09173084360.
Thank you very much and Happy Programming.
Sample Program Output
Program Listing
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
ofstream file("output.txt");
int square_cube(int x_value)
{
cout <<"\n\n";
cout <<setw(3)<< "\n Number" << setw(12)
<< "SQUARE" << setw(14)
<< "CUBE ROOT";
cout << "\n";
for (int y=1; y<= x_value; y+=1)
{
cout <<"\n"<<setw(5) << y << setw(12)
<< y * y << setw(12)
<< y * y * y;
}
file << "\t SQUARE AND CUBE ROOT VERSION 1.0";
file <<"\n\n";
file <<setw(3)<< "\n Number" << setw(12)
<< "SQUARE" << setw(14)
<< "CUBE ROOT";
file << "\n";
for (int y=1; y<= x_value; y+=1)
{
file <<"\n"<<setw(5) << y << setw(12)
<< y * y << setw(12)
<< y * y * y;
}
file.close();
cout << "\n\n";
system("pause");
}
main() {
ofstream file("output.txt");
int value=0;
cout << "\n\n";
cout << "\t SQUARE AND CUBE ROOT VERSION 1.0";
cout << "\n\n";
cout << "Enter a Number :=> ";
cin >> value;
square_cube(value);
}