Skip to content

Instantly share code, notes, and snippets.

@jatkins
Created January 29, 2016 08:28
Show Gist options
  • Save jatkins/d51206cf2cd1fce873ce to your computer and use it in GitHub Desktop.
Save jatkins/d51206cf2cd1fce873ce to your computer and use it in GitHub Desktop.
//Name: square cube charted
//Copyleft: Jacob Atkins 2006
//Author: Jacob Atkins
//Date: 11/10/06 09:56
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double square(double number); //function used to square numbers
double cube(double number); //function used to cube numbers
void chart(int number); // function used to output in a nice chart
int main(){//start of main
double userNumber = 0; //holds user input
cout << "Please Enter a number: ";
cin >> userNumber; //gets user input
chart(userNumber); //call to the chart function that takes care of eveything
system("pause");
return 0;
}//end of main
//function that outputs the chart
void chart(int number){//start of function
cout << "Number"
<< setw(15) << "Square"
<< setw(15) << "Cube" << endl; // prints header
cout << "-----------------------------------------\n"; //prints dashs below header
for(int i = 1; i <= number; i++){//start of for loop
cout << setw(15) << left << i // prints number
<< setw(17) << left << square(i) // prints number squared
<< setw(15) << left << cube(i) // prints number cubed
<< endl; // prints blank line
}// end of for loop
}//end of function
//function used to square numbers
double square(double number){//start of function
number = pow(number, 2.0); //sqaures the number
return number; //returns the number
}//end of function
//function used to cube number
double cube(double number){//start of function
number = pow(number, 3.0); //cubes the number
return number; //returns the number
}//end of function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment