Question

Write a Program that has a menu with a  layout below, that asks the user if they...

Write a Program that has a menu with a  layout below, that asks the user if they want to:

1. Converts from feet and inches to meter and centimeters

2. Converts from meter and centimeters to feet and inches

3. Quit the program

The program should continue as long as the user asks it to.

The program will use a switch statement for the menu option selection. Either a do loo or a do-while loop can be used for the overall program operation in main. Make sure your while or do-while statement is a conditional one (for example, while(loop=='y')) to keep looping.

Reminder to not use any global variables except for constants, which should be in caps.

Use a function for menu, the Eng2Metric and Metric2Eng functions which are not required to return not accept and inputs.

For example, the Eng2metric function will ask the user to enter the feet and inches and output the meters in a fraction as in something like 1.45 meters.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ code

============================================================================================

#include<iostream>

using namespace std;

void menu(int &opt)
{
   cout<<"1. Converts from feet and inches to meter and centimeters\n";
   cout<<"2. Converts from meter and centimeters to feet and inches\n";
   cout<<"3. Quit the program\n";
   cout<<"Enter your choice: ";
   cin>>opt;
}

void Metric2Eng()
{
       float feet,inches,meter,cm;
       cout<<"Enter the meter: ";
       cin>>meter;
       cout<<"Enter centimeter: ";
       cin>>cm;
       meter=meter+(cm/100);
       //cout<<"meter is :"<<meter<<endl;
       feet=3.281*meter;
       //cout<<"feet is: "<<feet<<endl;
      
       //find feet and incehs
       int feet1 = int(feet);
       double fractionalFoot = feet - feet1;
       inches = fractionalFoot * 12.0;
       cout<<"Height is: "<<feet1<<"ft and "<<inches<<" in"<<endl;
      
}

void Eng2Metric()
{
   float feet,inches,meter,cm;
   cout<<"enter the feet: ";
   cin>>feet;
   cout<<"enter the inches: ";
   cin>>inches;
   feet=feet+(inches/12);
  
   meter=0.305*feet;
   cm=meter*100;
   cout<<"Height is "<<meter<<" meter"<<endl;
  
}
int main()
{
char ch='y';
int opt;
do
{
   menu(opt);
   switch(opt)
   {
       case 1:
           Eng2Metric();
           break;
          
       case 2:
           Metric2Eng();
           break;
       case 3:
           return 0;
           break;
       default:
           cout<<"Wrong option selected\n";
          
   }
   cout<<"Do you want to continue(y/n): ";
   cin>>ch;
  
}while(ch=='y');

return 0;
}

============================================================================================

Output

Add a comment
Know the answer?
Add Answer to:
Write a Program that has a menu with a  layout below, that asks the user if they...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Programming 4th Edition: Write a program that asks the user for the number of feet....

    Python Programming 4th Edition: Write a program that asks the user for the number of feet. The program converts those feet to inches by using the formula ’12 * feet’. Hint: Define main () program Get the number of feet from the user Define variables Call a function feet_to_inches(feet) The function receives the number of feet and returns the number of inches in that many feet. The output should look like as follows: Enter the number of feet: If the...

  • Need help with following C++ program: 3) Write a program in C++ with a menu. When...

    Need help with following C++ program: 3) Write a program in C++ with a menu. When the program executes it gives the user a list of choice to choose from. The user can input 1,2 or 3 only. For all other input, the message “Invalid Options” will be displayed. ****MENU**** 1) Convert length from feet to inches. 2) Convert length from meter to centimeters. 3) To quit the program

  • Java COSC 237 Problem: You are to develop a program that allows a user to convert...

    Java COSC 237 Problem: You are to develop a program that allows a user to convert lengths in the metric system (i.e., meters/centimeters) to the Imperial system (i.e., feet/inches) AND convert lengths in the Imperial system to the metric system. Specifications • Input may be given with or without decimal places. • Error checking for invalid input is not required. • The results are to be displayed with two decimal places of precision. (For example, 2 meters, 25 centimeters (225...

  • 21 Write a program that asks the user to input the length and breadth of a...

    21 Write a program that asks the user to input the length and breadth of a soccer field, and then computes and returns the number of square meters of grass required to cover the field The formula for the area is the product of length and breadth (5) 22 The following program uses the break statement to terminate an infinite while loop to print 5 numbers Rewrite the program to use a while loop to display numbers from 1 to...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

  •   Write codes that will produce the screen as shown Firstly, the program prompts user to...

      Write codes that will produce the screen as shown Firstly, the program prompts user to enter his name. Then it will display Hello <user name>. Next it prints out a menu which contains 5 options (1- add two integers, 2- add two strings, 3- compute factorial, 4- reverse a string, 5- quit program). Code all 5 tasks appropriately. When the task is completed (not including quitting program of course), the menu pops up again and asks user to try...

  • java program QUESTION 2: 1. Write a do-while loop that asks the user to select a...

    java program QUESTION 2: 1. Write a do-while loop that asks the user to select a task from the following menu to continue: 1. Option 1 2. Option 2 3. Option 3 4. Option 4 5. Exit Read the selection from the keyboard then write the switch statement: For option 1, display the message "Do the option 1" For option 2, display the message "Do the option 2" For option 3, display the message "Do the option 3" For option...

  • CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c...

    CSC 130 Lab Assignment 8 – Program Menu Create a C source code file named lab8.c that implements the following features. Implement this program in stages using stepwise refinement to ensure that it will compile and run as you go. This makes it much easier to debug and understand. This program presents the user a menu of operations that it can perform. The choices are listed and a prompt waits for the user to select a choice by entering a...

  • C++ coding answer 5. Write a program that asks the user for a positive integer value....

    C++ coding answer 5. Write a program that asks the user for a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. Input Validation: Do not accept a negative starting number.

  • Write a program that displays this to the user. "Hot Beverage Menu" "A: Coffee $1.00", "B:...

    Write a program that displays this to the user. "Hot Beverage Menu" "A: Coffee $1.00", "B: Tea $ 0.75", "C: Hot Chocolate $1.25", "D: Cappuccino S2.50", "E: Exit Menu" Prompt the user to make a selection. Determine which item the user entered. Use a do-while loop that keeps repeating till the user selects E from the Menu. If the user has selected a valid beverage, prompt the user for how many cups they would like, and print out how much...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT