Question

In: Computer Science

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

Solutions

Expert Solution

#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!!!!


Related Solutions

Code in Java Change the instructionLabel to ask the user to enter a numeric value into...
Code in Java Change the instructionLabel to ask the user to enter a numeric value into the textField and click the button to convert the entered value from kilometers to miles (1.609344 km = 1 mile). When the actionButton on the form is clicked, ActionWindow should take the value entered in the textField, convert it from kilometers to miles, and display the result in the resultField. import java.awt.Container; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class...
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
Write a program that prompts the user to enter a person’s date of birth in numeric...
Write a program that prompts the user to enter a person’s date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Follow similar conventions for the invalid values of month and year. (Note that your program...
Write a Python program that asks the user to enter a student's name and 8 numeric...
Write a Python program that asks the user to enter a student's name and 8 numeric tests scores (out of 100 for each test). The name will be a local variable. The program should display a letter grade for each score, and the average test score, along with the student's name. Write the following functions in the program: calc_average - this function should accept 8 test scores as arguments and return the average of the scores per student determine_grade -...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric...
PYTHON Write a program that asks the user to enter a student's name and 8 numeric assignment scores (out of 100 for each assignment). The program should output the student's name, a letter grade for each assignment score, and a cumulative average for all the assignments. Please note, there are 12 students in the class so your program will need to be able to either accept data for 12 students or loop 12 times in order to process all the...
1. Write a program that will ask the user to enter a character and then classify...
1. Write a program that will ask the user to enter a character and then classify the character as one of the following using only IF-ELSE and logical operators. (50 points - 10pts for syntax, 10pts for commenting and 30pts for successful execution) • Integer • Lower Case Vowel • Upper Case Vowel • Lower Case Consonant • Upper Case Consonant • Special Character
Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
8. write a program using switch-case statements that ask a user to enter a temperature value...
8. write a program using switch-case statements that ask a user to enter a temperature value in degrees Fahrenheit (In your program, use an integer to record the user’s entry. If the temperature falls between 0 and 96 make it print “Temperature below normal”. If the temperature is 97, 98, make it “Temperature normal”. If the temperature is between 100 and 150, print “You have a fever”. If the temperature is outside the ranges given above, display “Are you human”....
write a program i java that ask the user to enter salary, user ID and username...
write a program i java that ask the user to enter salary, user ID and username and out put them
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT