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 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 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
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.
Write a program in C++ that converts a positive integer into the Roman number system. The...
Write a program in C++ that converts a positive integer into the Roman number system. The Roman number system has digits I      1 V    5 X    10 L     50 C     100 D    500 M    1,000 Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as...
write a program called GradeCalculator that will calculate the grading statistics of a desired number of...
write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will also check for negative scores. If any...
Write a program IN JAVA that asks the user for a number. The program should check...
Write a program IN JAVA that asks the user for a number. The program should check the number to ensure that it is valid (if not, the user should enter a valid number to continue.) The program should print out all of the prime numbers from 2 up to the number, with up to 10 numbers per line. (Recall: A prime number is a number that is only divisible by itself and 1.) The code should ask the user if...
Write a function called main which gets a single number, furlongs, from the user and converts...
Write a function called main which gets a single number, furlongs, from the user and converts that to meters and prints out the converted result. The math you need to know is that there are 201.16800 meters in a furlong. your results should yield something like these test cases. >>> main() How many furlongs? 10 your 10 furlongs are 2011.68 Meters >>> main() How many furlongs? 24 your 24 furlongs are 4828.032 Meters
In matlab.write a program that converts a numerical date given by the user into a month,...
In matlab.write a program that converts a numerical date given by the user into a month, day, and year. Specifically, the user should input a sequence of eight numbers 05141956. the program should print out the same date in complete format. In this example it would print "The date is May 14th, 1956". Notice the "th" addition after the day. This changes depending on the number. Make sure this feature is included. MATLAB has built-in date conversion functions. You cannot...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT