Question

In: Computer Science

Write a program that converts the user's number into the desired unit of measurement. The user...

Write a program that converts the user's number into the desired unit of measurement. The user will pick the desired unit from a menu shown below. Ask the follow-up question (the number to convert) and do the math ONLY if the user picks a valid choice from the menu. You can see the conversions / multipliers needed for this program in the output section below.

Menu/Prompt:

Enter the number that corresponds to your desired unit conversion from the choices below:
[1] Tablespoon (Tbsp) to Teaspoons (Tsp)
[2] Ounces (Oz) to Grams (g)
[3] Cups to Milliliters (ml)
Enter a number: 3

Possible Input/Output (Assume user enters the number 1 as the base unit)

Enter the number of tablespoons:

There are 3 teaspoons in 1 tablespoons

Enter the number of ounces:

There are 28.35 grams in 1 ounces

Enter the number of cups:

There are 236.6 ml in 1 cups

Invalid choice. Please run the program again.

Notes and Hints:

1) What programming structure is best for menus? Use that!

"Enter the number that corresponds to your desired unit conversion from the choices below:\n";
"[1] Tablespoon (Tbsp) to Teaspoons (Tsp)\n"
"[2] Ounces (Oz) to Grams (g)\n"
"[3] Cups to Milliliters (ml)\n"
"Enter a number: ";

cout << endl;


"Enter the number of tablespoons: ";

cout <<endl;

"There are " << YOUR CODE HERE<< " teaspoons in " << YOUR CODE HERE << " tablespoons";

"Enter the number of ounces: ";

cout << endl;

"There are " << YOUR CODE HERE<< " grams in " <<YOUR CODE HERE<< " ounces";

"Enter the number of cups: ";

cout << endl;

"There are " << YOUR CODE HERE << " ml in " <<YOUR CODE HERE << " cups";

"Invalid choice. Please run the program again.";

Solutions

Expert Solution

CODE FOR THE FOLLOWING PROGRAM :-

#include <iostream>

using namespace std;

int main()
{
    
    //Variables used in the program
    int choice;
    float tbsp,Oz,cups;
    do{
        //MENU for user to choose 
        cout<<"Enter the number that corresponds to your desired unit conversion from the choices below:\n";
        cout<<"[1] Tablespoon (Tbsp) to Teaspoons (Tsp)\n";
        cout<<"[2] Ounces (Oz) to Grams (g)\n";
        cout<<"[3] Cups to Milliliters (ml)\n";
        cout<<"Enter a number: ";
        //If user chooses 1
        cin>>choice;
        if(choice==1){
            cout<<"Enter the number of tablespoons: ";
            cin>>tbsp;
            //converting tablespoons to teaspoons
            cout<<"There are " << tbsp*3<< " teaspoons in " << tbsp << " tablespoons";
            cout<<endl;
        }
        //If user chooses 2 
        else if(choice==2){
            cout<<"Enter the number of ounces: ";
            cin>>Oz;
            //converting Ounces to grams
            cout<<"There are " << Oz*28.35<< " grams in " <<Oz<< " ounces";
            cout<<endl;
        }
        //if user chooses 3
        else if(choice==3){
            cout<<"Enter the number of cups: ";
            cin>>cups;
            //Converting cups to ml
            cout<<"There are " << cups*236.6 << " ml in " <<cups<< " cups"; 
            cout << endl;
        }
        else {  
            cout<<"Invalid choice. Please run the program again.";
        }
        
    }while(choice==1 || choice==2 || choice==3);

    return 0;
}

SCREENSHOT OF THE CODE AND SAMPLE RUN:-

SAMPLE RUN:-

HAPPY LEARNING


Related Solutions

C++ : Write a program that creates a login name for a user, given the user's...
C++ : Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first five letters of the last name, followed by the first letter of the first name, and then the last two digits of the number (use the % operator). If the last name has less than five letters, then use all letters of the...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a Python program that has the user enter their name.   Using the user's name calculate...
Write a Python program that has the user enter their name.   Using the user's name calculate the following: 1. How many letters are in the user's name? 2. Print the user's name in REVERSE both in capital letters and lowercase letters 3. Print the ASCII value for each letter of the user's name. 4. Print the SUM of all of the letters of the user's name (add each letter from #3)
Write a program(C#) that prompts the user for her home planet. Based on the user's input...
Write a program(C#) that prompts the user for her home planet. Based on the user's input the program will display the following: Input: earth Message: earth. You are an Earthling and you have 10 fingers Input: VENUS Message: VENUS. You are a Venusian and you have 12 fingers Input: Mars Message: Mars. You are a Martian and you have 8 fingers any other input Message: I am sorry I don't know of that planet You may use either the ToUpper()...
2) Write a program(C#) that prompts the user for her home planet. Based on the user's...
2) Write a program(C#) that prompts the user for her home planet. Based on the user's input the program will display the following: Input: earth Message: earth. You are an Earthling and you have 10 fingers Input: VENUS Message: VENUS. You are a Venusian and you have 12 fingers Input: Mars Message: Mars. You are a Martian and you have 8 fingers any other input Message: I am sorry I don't know of that planet You may use either the...
2. Create a C++ program that converts the number of American dollars entered by the user...
2. Create a C++ program that converts the number of American dollars entered by the user into one of the following foreign currencies: Euro, British pound, German mark, or Swiss franc. Allow the user to select the foreign currency from a menu. Store the exchange rates in a four-element double array named rates. Notice that the menu choice is always one number more than the subscript of its corresponding rate. For example, menu choice 1's rate is stored in the...
Write a program that accepts a number of minutes and converts it both to hours and...
Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100.0 hours or 4.166666666666667 days. (I currently have what is below) import java.util.Scanner; public class MinutesConversion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numOfMinutes = sc.nextInt(); double hour = numOfMinutes/60.00; double days = (hour/24); System.out.println(numOfMinutes + " minutes is " + hour + " hours or " + days + " days.");...
Write a program that accepts a number of minutes and converts it to days and hours....
Write a program that accepts a number of minutes and converts it to days and hours. For example, 6000 minutes represents 4 days and 4 hours. Be sure to provide proper exception handling for non-numeric values and for negative values. Save the file as  MinuteConversionWithExceptionHandling.java
create a program that will verify a user's login credentials. The program should prompt the user...
create a program that will verify a user's login credentials. The program should prompt the user to enter his/her username and password at the keyboard. Then it should read the data from a data file named "login.txt". The file "login.txt" will contain a list of 3 valid usernames and passwords to verify the login information supplied by a user.  If the username and password entered by the user matches one of the sets read from the file, the program should print...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change...
2. Write a program that asks for hexadecimal number and converts it to decimal. Then change it to convert an octal number to decimal in perl language.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT