Answer to Question #105878 in C++ for Aliasghar

Question #105878
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-03-22T17:04:22-0400
#include <iostream>

void feetAndInchesToMetersAndCent(int feet, double inches, int &meters, double &cent) {
    inches = 12 * feet + inches;
    cent = inches * 2.54;
    meters = cent / 100;
    cent -= meters * 100;
}

void metersAndCentTofeetAndInches(int meters, double cent, int &feet, double &inches) {
    cent = 100 * meters + cent;
    inches = cent / 2.54;
    feet = inches / 12;
    inches -= feet * 12;
}

void showChoices() {
    std::cout << "-------------------------------------------------\n";
    std::cout << "Choose convertation:\n";
    std::cout << "1) from feet and inches to meters and centimeters\n";
    std::cout << "2) from meters and centimeters to feet and inches\n";
    std::cout << "3) exit\n";
    std::cout << "> ";
    int choice;
    int feet, meters;
    double inches, cent;

    std::cin >> choice;
    if (choice == 1) {
        std::cout << "Enter feet: ";
        std::cin >> feet;
        std::cout << "Enter inches: ";
        std::cin >> inches;
        feetAndInchesToMetersAndCent(feet, inches, meters, cent);
        std::cout << "Meters: " << meters << "\n";
        std::cout << "Centimeters: " << cent << "\n\n";
    }
    else if (choice == 2) {
        std::cout << "Enter meters: ";
        std::cin >> meters;
        std::cout << "Enter centimeters: ";
        std::cin >> cent;
        metersAndCentTofeetAndInches(meters, cent, feet, inches);
        std::cout << "Feet: " << feet << "\n";
        std::cout << "Inches: " << inches << "\n\n";
    }
    else if (choice == 3) {
        exit(0);
    }
}

int main()
{
    while (true) {
        showChoices();
    }
}

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