Question

Digit to WordsWrite a C program that asks the user for a two-digit number, then prints...

Digit to WordsWrite a C program that asks the user for a two-digit number, then prints the English wordfor the number. Your program should loop until the user wants to quit.Example:Enter a two-digit number: 45You entered the number forty-five.Hint: Break the number into two digits. Use one switch statement to print the word for the firstdigit (“twenty,” “thirty,” and so forth). Use a second switch statement to print the word for thesecond digit. Don’t forget that the numbers between 11 and 19 require special treatment.

i need help how to both enter both digits on the same line

this is my program

#define _CRT_SECURE_NO_WARNINGS
#include <stdio>

int main(void) {
   int num1;
   int num2;


       printf("<<<<<>>>>>>>\n");
       printf("Enter 2 digits from 00 to 99:\n");
       printf("Enter the first single digit: \n");
       scanf("%d", &num1);
       printf("Enter the second single digit: \n");
       scanf("%d", &num2)


.....

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
void first_number(int n)
{
switch(n)
{
case 1:
printf("Ten");
break;
case 2:
printf("Twenty ");
break;
case 3:
printf("Thirty ");
break;
case 4:
printf("Forty ");
break;
case 5:
printf("Fifty ");
break;
case 6:
printf("Sixty ");
break;
case 7:
printf("Seventy ");
break;
case 8:
printf("Eighty ");
break;
case 9:
printf("Ninety ");
break;
}
}
void second_number(int n)
{
switch(n)
{
case 1:
printf("One");
break;
case 2:
printf("Two");
break;
case 3:
printf("Three");
break;
case 4:
printf("Four");
break;
case 5:
printf("Fife");
break;
case 6:
printf("Six");
break;
case 7:
printf("Seven");
break;
case 8:
printf("Eight");
break;
case 9:
printf("Nine");
break;
}
}
void num_btw_11_to_19(int n)
{
switch(n)
{
case 11:
printf("Eleven");
break;
case 12:
printf("Twelve");
break;
case 13:
printf("Thirteen");
break;
case 14:
printf("Fourteen");
break;
case 15:
printf("Fifteen");
break;
case 16:
printf("Sixteen");
break;
case 17:
printf("Seventeen");
break;
case 18:
printf("Eighteen");
break;
case 19:
printf("Nineteen");
break;
}
}
int main()
{
char num[2],c;
while(1)
{
printf("Enter 2 digits from 00 to 99:\n");
scanf("%s",num);
int n=((num[0]-48)*10+(num[1]-48));
if(n>10&&n<20)
num_btw_11_to_19(n);
else if((num[1]-48)==0)
first_number(num[0]-48);
else if((num[0]-48)==0)
second_number(num[1]-48);
else
{
first_number(num[0]-48);
second_number(num[1]-48);
}
printf("\nPress Q/q to Quit :");
fflush(stdin);
scanf("%c",&c);
if(c=='Q'||c=='q')
break;
}
}

Add a comment
Know the answer?
Add Answer to:
Digit to WordsWrite a C program that asks the user for a two-digit number, then prints...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program that prompts the user to enter two positive integers: num1 and num2....

    C++ Write a program that prompts the user to enter two positive integers: num1 and num2. - Validate that num1 is less than num2 and that both numbers are positive. If any of these conditions are not met, allow the user to re-enter num1 and num2 until the input is determined valid. - For all integers from num1 through num2, print the word keyboard if the current integer is divisible by 2 and print the word mouse if the current...

  • Hi, this program is in C. Can you a pass by pointer in this program. Thanks. #include //function ...

    Hi, this program is in C. Can you a pass by pointer in this program. Thanks. #include //function declaration/prototype here int main(int argc, char * argv[]) { int num1, num2;    printf("Please enter two integers (separated by ,):\n"); scanf("%d,%d", &num1, &num2); //enter two integers separated by a comma (,)    printf("num1 stores: %d\n", num1); printf("num2 stores: %d\n", num2);    /*make a function call to make sure the followings are true after we call the function (1) variable num1 stores the larger value after...

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...

  • Write a program that asks the user to input a 4-digit integer and then prints the...

    Write a program that asks the user to input a 4-digit integer and then prints the integer in reverse. Your program needs to implement a function reverse that will take in as input the 4-digit number and print it out in reverse. Your code will consist of two files: main.s and reverse.s. Main.s will ask for the user input number and call the function reverse. For ARM/Data Structure needs to be able to run on Pi Reverse.s will take in...

  • So the assignment is to write a program that have the user entered 3 numbers and...

    So the assignment is to write a program that have the user entered 3 numbers and than it will sort it by ascending order. Here are the code I wrote, but it won't compiled and I kept on getting an error message "Using uninitiazed memory" for all the variables. Can someone please help take a look and see whats going on? #include <iostream> using namespace std; int main() { //variables int num1, num2, num3; int lowest, middle, highest; //user inputs...

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • May i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #...

    may i ask for help with this c++ problem? this is the code i have for assignment 4 question 2: #include<iostream> #include<string> #include<sstream> #include<stack> using namespace std; int main() { string inputStr; stack <int> numberStack; cout<<"Enter your expression::"; getline(cin,inputStr); int len=inputStr.length(); stringstream inputStream(inputStr); string word; int val,num1,num2; while (inputStream >> word) { //cout << word << endl; if(word[0] != '+'&& word[0] != '-' && word[0] != '*') { val=stoi(word); numberStack.push(val); // cout<<"Val:"<<val<<endl; } else if(word[0]=='+') { num1=numberStack.top(); numberStack.pop(); num2=numberStack.top(); numberStack.pop();...

  • Write a C program which calculates how many digits a number has and prints each digit...

    Write a C program which calculates how many digits a number has and prints each digit in reserve order with space in between(no space after the last digit). The number > 0 and has no more than 5 digits. (optional] It is better to write two functions. One is designed for printing number in reverse order and the other is for counting the number of digits. Given that the value of number (which is an int variable) is 12345, the...

  • This code should exit in 0 is inputed or the code should repeat adding two number...

    This code should exit in 0 is inputed or the code should repeat adding two number if '1' is inputed. What are three logical or/and syntax errors in this code? int choice, numi, num2: Linn printf("Enter a number: "); scanf("%d", &numl); printf("Enter another number: "); scanf("%d", &num2); printf ("Their sum is d\n", (numl+num2)); printf ("Enter 1 to repeat, 0 to exit"); scanf("%d", &choice) } while (choice == 0) HH

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT