1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <cstdlib>
#include <iostream>
#include <cmath> // For math functions. eg SIN, COS, TAN.
#define PI 3.14159 // Define the word PI and assign its value.
using namespace std;
int main()
{
double Angle, Opposite, a, e, area, radius, circumference, result, radians; // Variables for cirumference, area and hypotenuse.
int choice;
int n, count; // Variables for factorial.
int factorial=1;
do // This is the menu. While-loop repeats statement while the expression is true.
{
cout << "WHICH CALCULATION DO YOU REQUIRE?\n\n"; // \n for a new line.
cout << "Option 1 to calculate the circumference of a circle.\n";
cout << "Option 2 to calculate the area of a circle.\n";
cout << "Option 3 to calculate the hypotenuse of a triangle.\n";
cout << "Option 4 to calculate the factorial of a number.\n";
cout << "Option 5 to EXIT the program!\n\n"; // \n\n for two spaces for a new line.
cout << " Choice: ";
cin >> choice;
while ((choice < 1) || (choice > 5))
{
cout << "Incorrect choice. Please choose between 1 and 5. ";
cin >> choice;
}
if (choice == 5)// Loads option 5.
{ system ("cls");
cout << "Terminating Program!\n";
system ("pause");
return (0);// Exit the program.
}
else if (choice == 1) // If this condition is true, the statement is executed. If choice is equal to 1.
{ //selection 1 code
}
else if (choice == 2)// Loads option 2.
{ selection 2 code
}
else if (choice == 3)// Loads option 3.
{ selection 3 code
}
else if (choice == 4)// Loads option 4.
{ system ("cls");
cout << "Here you can calculate the factorial of a number between 1 and 30.\n";
system ("pause");
cout << "Please enter a number between 1 and 30: \n";// Limit the user so it doesnt bug out with a high number.
cin>>n;
for( count = n; count > 1; count--)// Counts backwards, so the factorial of 5 = 5x4x3x2x1, which is 120.
factorial = (factorial * count);
cout << "The factorial equals: " << factorial <<endl;
system ("pause");
system ("cls");
}
}while (1);// End of loop. (1)
}// End of main.
|