Advertisement
Guest User

Ref Functions? Easy

a guest
Jul 27th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. /*
  2.     Rectangle Area v1
  3.     Created by Julio Milian
  4.     July 27, 2016
  5.  
  6.     This program will calculate the area
  7.     of a rectangle based on users length
  8.     and width.
  9. */
  10.  
  11. #include <iostream>
  12. using namespace std;
  13.  
  14.  
  15. int main(){
  16.  
  17.     //function prototypes
  18.     double getLength(int &);
  19.     double getWidth(int &);
  20.     double getArea(double &, double &);
  21.     void displayData(double &, double &, double &);
  22.  
  23.     //VARIABLES
  24.     int length = 0;
  25.     int width = 0;
  26.     double newLen = 0.0;
  27.     double newWid = 0.0;
  28.     double area = 0.0;
  29.  
  30.     for (;;){
  31.  
  32.         cout << "Rectangle Area v1\n";
  33.         cout << "Enter -1 as a value if wish to quit!\n";
  34.         cout << "-------------------------------------\n";
  35.         cout << "What is the lenght? ";
  36.         cin >> length;
  37.         if (length != -1){
  38.             cout << "What is width? ";
  39.             cin >> width;
  40.             newLen = getLength(length);
  41.             newWid = getWidth(width);
  42.             area = getArea(newLen, newWid);
  43.             displayData(newLen, newWid, area);
  44.         }
  45.         else if(length <= 0 && length != -1)
  46.             cout << "\nNo negative numbers!";
  47.         else{
  48.             cout << "\n\nExiting. . . ";
  49.             return 0;
  50.         }//end if
  51.         system("Pause");
  52.         system("CLS");
  53.     }//end for
  54.  
  55.     return 0;
  56. }//end main
  57.  
  58. //-------Functions--------
  59. double getLength(int &ref){
  60.     double one = 1.0;
  61.     ref = ref * one;
  62.     return ref;
  63. }
  64.  
  65. double getWidth(int &ref){
  66.     double one = 1.0;
  67.     ref = ref * one;
  68.     return ref;
  69. }
  70.  
  71. double getArea(double &refa, double &refb){
  72.     double area = 0.0;
  73.     area = refa * refb;
  74.     return area;
  75. }
  76.  
  77. void displayData(double &refa, double &refb, double &refc){
  78.     cout << "\nResults\n";
  79.     cout << "--------------------------------------\n";
  80.     cout << "The length of the rectangle is: " << refa;
  81.     cout << "\nThe widht of the rectangle is: " << refb;
  82.     cout << "\nThe area of the rectangle is: " << refc << "\n\n";
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement