Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //Functions
  5. int Square(int);
  6. int Cube(int);
  7.  
  8. int main()
  9. {
  10.     //Variables
  11.     int num;          //user input
  12.     int square;       //Holds the square of num
  13.     int cube;        //Holds the cube of num
  14.    
  15.     //Purpose
  16.     cout << "Purpose of the program: To take a user input, and display the square, and cube of it." << endl;
  17.    
  18.     //Get input
  19.     cout << "Please enter an integer: ";
  20.     cin >> num;
  21.     cout << "You have entered: " << num << endl;
  22.    
  23.     //Compute the square and cube
  24.     square = Square(num);    //Calls the Square function
  25.     cube = Cube(num);        //Calls the cube function
  26.    
  27.     //Display the square and cube of a number
  28.     cout << "The square of " << num << " is " << square << endl;
  29.     cout << "The cube of " << num << " is " << cube << endl;
  30.     return 0;
  31. }
  32.  
  33. int Square(int x)
  34. {
  35.     return x * x;
  36. }
  37.  
  38. int Cube(int x)
  39. {
  40.     return x * x * x;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement