Advertisement
Felanpro

Square Area Calculator

Dec 27th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     play:
  10.     //Declarations
  11.     double base, height;
  12.  
  13.     //Start
  14.     cout << "\a" << endl;
  15.     cout << "--Square Area Calculator (cm2)--" << endl;
  16.     cout << "*******************************" << endl;
  17.     system("pause");
  18.     cout << "" << endl;
  19.  
  20.     //Inputs
  21.     cout << "Base of square: ";
  22.     cin >> base;
  23.     cout << "Height of square: ";
  24.     cin >> height;
  25.     system("pause");
  26.  
  27.     //Result declarations
  28.     double areaResult = base * height;
  29.     double halfArea = areaResult / 2;
  30.  
  31.     //Display results
  32.     cout << areaResult << "cm2" << endl;
  33.     cout << "Half of the area is " << halfArea << "cm2" << endl;
  34.     system("pause");
  35.  
  36.     retryOption:
  37.     //Retry declaration variable
  38.     string retryAnswer;
  39.  
  40.     //Retry option
  41.     cout << "Want to calculate the area of another square? y=yes n=no: ";
  42.     cin >> retryAnswer;
  43.  
  44.     if (retryAnswer == "y")
  45.     {
  46.         cout << "\a" << endl;
  47.         system("cls");
  48.         goto play;
  49.     }
  50.     else if (retryAnswer == "n")
  51.     {
  52.         exit;
  53.     }
  54.     else
  55.     {
  56.         cout << "Invalid answer, choose y or n." << endl;
  57.         goto retryOption;
  58.     }
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement