Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please help me ,I want to write a program as follows in C++ language .Insert a number from 20 to 90 and print his name by using the Switch phrase.
Posted
Updated 1-Nov-10 9:33am
v2
Comments
TheyCallMeMrJames 1-Nov-10 15:33pm    
What part of the code are you having trouble with? Could you show us where you're at? What have you tried?

If you must 'cheat' on your homework then at least do it in a semi-anonymous way. :)

Use a search engine with a suitable search term. I don't know, something like c++ number to words, or similar.
 
Share this answer
 
First, separate your given number in to tens and ones. (e.g. if your number is 23, int tens = 2; and int ones = 3;.) You can use the modulus operator to accomplish this programmatically.

Next, use a switch statement to print the name of the tens digit.
switch( tens )
{
case 2:
    printf("twenty");
case 3:
    printf("thirty");
// ...
}


Finally, use a second switch statement to print the name of the ones digit:
switch( ones )
{
case 1:
    printf("one")
case 2:
    printf("two");
// ...
}


That's it!

-PaulH

Edit: It looks to me like he's asking for guidance, not cheating.
 
Share this answer
 
v3
Comments
Dalek Dave 1-Nov-10 19:31pm    
Why not just switch 20 to 90 individually.
Not as neat but easier for cut and paste merchants :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900