Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Rectangle Area v1
- Created by Julio Milian
- July 27, 2016
- This program will calculate the area
- of a rectangle based on users length
- and width.
- */
- #include <iostream>
- using namespace std;
- int main(){
- //function prototypes
- double getLength(int &);
- double getWidth(int &);
- double getArea(double &, double &);
- void displayData(double &, double &, double &);
- //VARIABLES
- int length = 0;
- int width = 0;
- double newLen = 0.0;
- double newWid = 0.0;
- double area = 0.0;
- for (;;){
- cout << "Rectangle Area v1\n";
- cout << "Enter -1 as a value if wish to quit!\n";
- cout << "-------------------------------------\n";
- cout << "What is the lenght? ";
- cin >> length;
- if (length != -1){
- cout << "What is width? ";
- cin >> width;
- newLen = getLength(length);
- newWid = getWidth(width);
- area = getArea(newLen, newWid);
- displayData(newLen, newWid, area);
- }
- else if(length <= 0 && length != -1)
- cout << "\nNo negative numbers!";
- else{
- cout << "\n\nExiting. . . ";
- return 0;
- }//end if
- system("Pause");
- system("CLS");
- }//end for
- return 0;
- }//end main
- //-------Functions--------
- double getLength(int &ref){
- double one = 1.0;
- ref = ref * one;
- return ref;
- }
- double getWidth(int &ref){
- double one = 1.0;
- ref = ref * one;
- return ref;
- }
- double getArea(double &refa, double &refb){
- double area = 0.0;
- area = refa * refb;
- return area;
- }
- void displayData(double &refa, double &refb, double &refc){
- cout << "\nResults\n";
- cout << "--------------------------------------\n";
- cout << "The length of the rectangle is: " << refa;
- cout << "\nThe widht of the rectangle is: " << refb;
- cout << "\nThe area of the rectangle is: " << refc << "\n\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement