Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //This is prototyping the functions for later when the if statement calls for a function.
- int triangle();
- int circle();
- int square();
- int main()
- {
- cout << "Welcome to my area calculator,\n please select a shape using the numbers as a selection.\n\n" << "1.Triangle\n2.Circle\n3.Square\n";
- int selection;
- cin >> selection;
- cout << endl;
- if (selection == 2){
- circle();
- }
- if (selection>3){ //This if statement checks if the selection is valid or not, currently works for numbers but not text.
- cout << "Sorry that wasn't one of the options.";
- main();
- }
- //the if statements below check which shape was selected to begin the calculation.
- if(selection == 1){
- triangle();
- }
- if (selection == 2){
- circle();
- }
- if (selection == 3){
- square();
- }
- return 0;
- }
- //Below are the functions for each calculations
- int triangle(){
- int base;
- int height;
- cout << "Please enter the base length of your triangle : ";
- cin >> base;
- cout << " \n\nPlease enter the Height of your triangle : ";
- cin >> height;
- cout << "The area of the triangle is : ";
- int triangle;
- triangle = (height + base) / 2;
- cout << triangle;
- return triangle;
- }
- int circle(){
- int radius;
- cout << "Please enter the radius of the circle : ";
- cin >> radius;
- cout << "\n\nThe area of the circle is : ";
- double circle;
- circle = 3.14 * radius * radius;
- cout << circle;
- return circle;
- }
- int square(){
- double width;
- double height;
- cout << "Please enter the height of your square : ";
- cin >> height;
- cout << "\n\nPlease enter the width of your square : ";
- cin >> width;
- int square;
- square = width * height;
- cout << "\n\nThe area of the square is : " << square;
- return square;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement