Skip to content

Commit 558eca4

Browse files
Create feet_to_inches.cpp
1 parent 576c179 commit 558eca4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Funtions/feet_to_inches.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//Prograam to convert distance in feet or inches using a call by reference method
2+
3+
#include <iostream>
4+
using namespace std;
5+
void convert(int &, char &, char);
6+
int main()
7+
{
8+
int distance;
9+
char choice, type = 'F';
10+
cout << "Enter distance in feets:" << endl;
11+
cin >> distance;
12+
cout << "You want your distance in feets/inches?(F/I):" << endl;
13+
cin >> choice;
14+
switch (choice)
15+
{
16+
case 'F':
17+
convert(distance, type, 'F');
18+
break;
19+
case 'I':
20+
convert(distance, type, 'I');
21+
break;
22+
default:
23+
cout << "Wrong choice entered:" << endl;
24+
exit(0);
25+
}
26+
27+
cout << "Distance=" << distance << type << endl;
28+
}
29+
void convert(int &distance, char &type, char choice)
30+
{
31+
if (choice == 'F')
32+
return;
33+
else if (choice == 'I')
34+
{
35+
distance = distance * 12;
36+
type = 'I';
37+
}
38+
return;
39+
}
40+
41+
/*****************
42+
Output:
43+
44+
Enter distance in feets:
45+
15
46+
You want your distance in feets/inches?(F/I):
47+
I
48+
Distance=180I
49+
50+
*****************/

0 commit comments

Comments
 (0)