Question

Write a program and ask a user to enter a numeric value between 0 - 99....

Write a program and ask a user to enter a numeric value between 0 - 99. Your program will spell out the numbers into words. You must use at least three switch cases in addition to multiple if statements. Each missing switch statement will reduce your grade for this problem by 20%. Note: The total number of if statements and switch cases should not exceed 28. Additional if/case statement will further reduce your grade by 5%.

in c++ please

Homework Answers

Answer #1
#include<iostream>
using namespace std;
int main()
{
        int num,tens_digit=-1,units_digit=-1;//decalring variables for number ,stroing unita and tens digit of number
        string units="",tens="";//strings for units and tens digit
        cout<<"Enter the number from 0 - 99"<<endl;
        cin>>num;//reading number
        units_digit=num%10;//retrieving units digit of the number
        num=num/10;
        tens_digit=num%10;
        //retrieving units digit of the number
        if(tens_digit==1 )//(1st if)if the number is between 10 to 19 this if condition is true.
        {
        switch(units_digit)//(contains 10  cases 10+1 if = 11)
                 {
            case 0: cout<<"Ten";
                        break;
            case 1: cout<<" Eleven";
                        break;
            case 2: cout<<"Twelve"; 
                        break;
            case 3: cout<<"Thirteen"; 
                        break;
            case 4: cout<<" Fourteen";
                        break;
            case 5: cout<<" Fifteen"; 
                        break;
            case 6: cout<<" Sixteen"; 
                        break;
            case 7: cout<<" Seventeen"; 
                        break;
            case 8: cout<<" Eighteen"; 
                        break;
            case 9: cout<<" Ninteen"; 
                        break;
        }
        return 0;// here the program will end if number is between 10 to 19 because there is no need to check for other switch statements.
    }
    switch(tens_digit) //(contains 8 cases 11+8=19)used to determine the value for tens digit
        {
                        
                case 2: tens="Twenty";
                break;
                case 3: tens="Thirty";
                break;
                case 4: tens="Fourty";
                break;
                case 5: tens="Fifty";
                break;
                case 6: tens="Sixty";
                break;
                case 7: tens="Seventy";
                break;
                case 8: tens="Eighty";
                break;
                case 9: tens="Ninety";
                break;
                default: units="Zero";//used to print 0
        }
        switch(units_digit)//(contains 9 cases 19+9=28)used to determine the value for units digit
        {
                case 1: units="One";
                break;
                case 2: units="Two";
                break;
                case 3: units="Three";
                break;
                case 4: units="Four";
                break;
                case 5: units="Five";
                break;
                case 6: units="Six";
                break;
                case 7: units="Seven";
                break;
                case 8: units="Eight";
                break;
                case 9: units="Nine";
                break;
                
        }
        cout<<tens << units;
        return 0;
        
}

Please comment if you have any doubts.

Rate please!!!!

Know the answer?
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
Similar Questions
python Write a program to find the largest value. Ask the user to enter three numbers....
python Write a program to find the largest value. Ask the user to enter three numbers. Compare them and report the largest one. [Hint: The user is free to enter any three numbers. Some or all of them may be the same. Take this into consideration when you compare the numbers.] The following are some examples. Enter first number: 7 Enter second number: 14 Enter third number: 10.5 The largest number is: 14.0 Enter first number: 17 Enter second number:...
Write a program that does the following in order: 1. Ask user to enter a name...
Write a program that does the following in order: 1. Ask user to enter a name 2. Ask the user to enter five numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 3. Calculate the sum of the numbers “amount1”, “amount2”, “amount3”, “amount4”, “amount5” 4. If the sum is greater than 0, print out the sum 5. If the sum is equal to zero, print out “Your account balance is zero” 6. If the sum is less than 0, print out “Your account...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Python programming Write a program that prompts the user to input the three coefficients a, b,...
Python programming Write a program that prompts the user to input the three coefficients a, b, and c of a quadratic equationax2+bx+c= 0.The program should display the solutions of this equation, in the following manner: 1. If the equation has one solution, display ONE SOLUTION:, followed by the solution, displayed with4 digits printed out after the decimal place. 2. If the equation has two real solutions, display TWO REAL SOLUTIONS:, followed by the two solutions, each displayed with4 digits printed...
C++. Write a program that draws a rocket shape on the screen based on user input...
C++. Write a program that draws a rocket shape on the screen based on user input of three values, height, width and stages. The type of box generated (i.e.. a hollow or filled-in) is based on a check for odd or even values input by the user for the box height (or number of rows). Here is the general specification given user input for the height of the box..... Draw a hollow box for each stage if the value for...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number...
Use Python 3.8: Problem Description Many recipes tend to be rather small, producing the fewest number of servings that are really possible with the included ingredients. Sometimes one will want to be able to scale those recipes upwards for serving larger groups. This program's task is to determine how much of each ingredient in a recipe will be required for a target party size. The first inputs to the program will be the recipe itself. Here is an example recipe...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT