|
-
April 5th, 2008, 04:59 AM
#1
Need Help/Hint C++
Write a Program in C++ that take input of the number from User and print this number its English number.
Sample Output:
Enter any number: 52
Number you enter is Fifty Two
Note:
You can use only and only if condition.
Range of number can be from 0 to 99.
The Problem is I Have to Use IF Condition and some Efficient Way, like not 100 comparisons...
I just Want to need help or hint in its algo or logic so i can make it in C++.
With Many Thanks.
-
April 5th, 2008, 05:24 AM
#2
Re: Need Help/Hint C++
 Originally Posted by butt_usman
Write a Program in C++ that take input of the number from User and print this number its English number.
Sample Output:
Enter any number: 52
Number you enter is Fifty Two
Note:
You can use only and only if condition.
Range of number can be from 0 to 99.
The Problem is I Have to Use IF Condition and some Efficient Way, like not 100 comparisons...
1) Create an array of names up to the word "nineteen":
"zero", "one", "two", "three", ... "nineteen"
2) Create another array with the words "twenty", "thirty", up to "ninety".
"twenty", "thirty", "forty", "fifty", ... "ninety"
3) If the number is less than 20, use the value as an index in the first array, and you have the answer.
4) If the number is greater than or equal 20,
a) divide the number by 10 to get the left digit. That number minus 2 is an index into the second array.
b) Do mod 10 on the original number to get the remainder. This will be the right digit. If the right digit is greater than 0, this is the index in the first array of the name.
For example:
Example 1:
Input: 4
array1[4] = "four" (finished)
Example 2:
Input: 35
this is greater than 20. So divide by 10:
35 / 10 = 3
array2[3-2] = array2[1] = "thirty".
Do a mod 10 on 35:
35 mod 10 = 5.
Since 5 is greater than 0, this is the index in the first array:
"thirty" array1[5]
"thirty" "five" -> thirty five.
Regards,
Paul McKenzie
-
April 6th, 2008, 11:29 AM
#3
Re: Need Help/Hint C++
Thanks Alot Man, It Really Helped Alot, Actually the Algorithm i Selected was using more Comparisons, ALthough Array can shorten it , but i m forced to use ONLY IF Conditions..
Mods can Close the Topic !
-
April 6th, 2008, 12:01 PM
#4
Re: Need Help/Hint C++
 Originally Posted by butt_usman
Thanks Alot Man, It Really Helped Alot, Actually the Algorithm i Selected was using more Comparisons, ALthough Array can shorten it , but i m forced to use ONLY IF Conditions..
What does if() conditions have to do with arrays?
That's like saying "I can only use a car, but not drink water". Driving a car and drinking water have nothing to do with each other.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|