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
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...
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...
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...
Question 1 of 15 Which of the following is not a recommended starting point to enter...
Question 1 of 15 Which of the following is not a recommended starting point to enter sales of products/services? A. Quick Create > Invoice B. Register > New transaction C. Quick Create > Sales Receipt D. Customer detail page > New transaction E. Transactions > Sales > New transaction Question 2 of 15 Which of the following statements accurately describes bank rules? A. Bank rules are imported from the Bank's website into the For Review tab in the Banking Center...
Fancy Millwork has a factory that produces custom kitchen cabinets. It has multiple product lines. Materials...
Fancy Millwork has a factory that produces custom kitchen cabinets. It has multiple product lines. Materials and labor for the cabinets are determined by each job. To simplify the assignment, we will assume the following average costs. The company estimates that it will have 32,000 direct labor hours in total for the kitchen cabinets. The materials include $2,000 for the wood and other materials on a per job basis. It requires 40 hours of labor on average for a custom...
Explain the complete HAZOP procedure as followed in the industry. See summary below. Explain all the...
Explain the complete HAZOP procedure as followed in the industry. See summary below. Explain all the main parts of HAZOP study in details given in the Pdf file including: 1. Overview (including definitions and usage) 2. Hazop methodology (including phases like definition, preparation, examination, documentation and follow-up). Give examples also 3. Risk review 4. Risk communication Guidance: Study the procedure carefully and then write the answers in your own words. Hazard & Operability Analysis (HAZOP) 1   Overview: Hazard and Operability...