File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ *****************/
You can’t perform that action at this time.
0 commit comments