Answer to Question #102701 in C++ for Aliasghar Ezzy

Question #102701
Write a menu-driven program which converts length from feet and inches to meters and centimeters and vice versa. The program should contain three functions: showChoices, feetAndInchesToMetersAndCent, and metersAndCentTofeetAndInches. The function showChoices informs the user how to use the program. The user has the choice to run the program as long as the user wishes. (You should use both value and reference parameters for this program)
1
Expert's answer
2020-02-10T03:51:04-0500
#include "pch.h"
#include <iostream>


using namespace std;


void showChoices();


void feetAndInchesToMetersAndCent(double feet, double inches, double &meters, double &cent);


void metersAndCentTofeetAndInches(double meters, double cent, double &feet, double &inches);


int main()
{
	double v1, v2; // source data
	double r1, r2; // result


	short int choice;


	for (;;) {
		showChoices(); // show information


		cout << '\n';


		cin >> choice; // 1,2 or -1


		cout << '\n';


		if (choice == -1) break; // exit


		else if (choice == 1) {


			cout << "Meters and centimeters to feet and inches\n";
			cout << "Enter first value: ";
			cin >> v1;
			cout << "Enter second value: ";
			cin >> v2;


			metersAndCentTofeetAndInches(v1,v2,r1,r2); // converting meters and centimeters to feet and inches
			
			cout << v1 << " meters and " << v2 << " cents = " << r1 << " feet and " << r2 << " inches\n\n";
		}
		else if (choice == 2) {


			cout << "feet and inches to meters and centimeters\n";
			cout << "Enter first value: ";
			cin >> v1;
			cout << "Enter second value: ";
			cin >> v2;


			feetAndInchesToMetersAndCent(v1,v2,r1,r2); // converting feet and inches to meters and centimeters


			cout << v1 << " feet and " << v2 << " inches = " << r1 << " meters and " << r2 << " cents\n\n";
		}
		else cout << "Unknown value, try again\n";


	} 


	return 0;
}


void showChoices() { // show information
	cout << "1 - meters and centimeters to feet and inches\n";
	cout << "2 - feet and inches to meters and centimeters\n";
	cout << "After selecting, enter 2 values(meters and centimeters, or feet and inches). -1 to exit\n";
}


void feetAndInchesToMetersAndCent(double feet, double inches, double &meters, double &cent) {
	// 1 feet = 0.3048 meters


	meters = feet * 0.3048;


	// 1 inch = 2.54 cent


	cent = inches * 2.54;
}


void metersAndCentTofeetAndInches(double meters, double cent, double &feet, double &inches) {
	// 1 meter = 3.28084 feet


	feet = meters * 3.28084;


	//1 cent = 0.393701 inches


	inches = cent * 0.393701;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS