-
Notifications
You must be signed in to change notification settings - Fork 1
/
passByRef.cpp
52 lines (42 loc) · 1.01 KB
/
passByRef.cpp
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
#include <iostream>
#include <conio.h>
#include <cmath>
using namespace std;
float getArea(float s);
float getArea(float l, float w);
int main()
{
float side = 0, len = 0, wid = 0;
int choice = 0;
char ans = ' ';
do {
system("cls");
cout << "\n[1] Area of square\n[2] Area of rectangle\n";
cout << "Choice: ";
cin >> choice;
if (choice == 1)
{
cout << "Enter side: ";
cin >> side;
cout << "Area is: " << getArea(side);
}
else if (choice == 2)
{
cout << "Enter length: ";
cin >> len;
cout << "Enter width: ";
cin >> wid;
cout << "Area is: " << getArea(len, wid);
}
cout << "\nTry another? [y/n]: ";
cin >> ans;
} while (toupper(ans) == 'Y');
getch();
return 0;
}
float getArea(float s) {
return (pow(s, 2));
}
float getArea(float l, float w) {
return (l * w);
}