Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

PWhermn

i'm hitting a brick wall

This topic is 6016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I hope this will fit in this forum asI am a beginner. I''m currently using the book "Turbo C++ Programming 101" by Greg Perry, Published by Sams. I''m going to write the exercise down because I am in desperate need of a hint on how to proceed. (From the lesson Logical Operators: Combining Relational Operators) Write a program that asks the user for a number between 100 and 9999. Write the word description of the number the user enters. For example, if the user enters 576, your program should print Five Hundred Seventy Six Don''t worry about putting hyphens between the numbers. I posted this quite awhile back on another newsgroup but I received the reply that it was okay to skip this exercise as all it related to was busy work. I''d rather know how to accomplish it. Can anyone give me some hints? I am stumped! Mike

Share this post


Link to post
Share on other sites
Advertisement
Just some doodling...
      
char * names = { "", "one ", "two ", "three ", "four ", "five ",
"
six ", "seven ", "eight ", "nine " };
char * twentyplus = { "
", "", "twenty ", "thirty ", "forty ", "fifty ",
"
sixty ", "seventy ", "eighty ", "ninety ";
char * teens = { "
ten ", "eleven", "twelve ", "thirteen ", "fourteen ",
"
fifteen ", "sixteen ", "seventeen ", "eighteen ", "nineteen " };

int number = 576;

int thousands = number/1000;
if(thousands)
cout << names[thousands] << "
thousand ";
number -= thousands*1000;

int hundreds = number/100;
if(hundreds)
cout << names[hundreds] << "
hundred ";
number -= hundreds*100;

int tens = number/10;
number -= tens*10;

if(tens == 1)
cout << teens[number] << "
\r\n";
else
cout << twentyplus[tens] << names[number] << "
\r\n";

The best way to learn programming is reading through it slowly. Read through it line by line, step by step, just as the program will run. It''ll make sense.

---email--- Tok ----surf----
~The Feature Creep of the Family~

Share this post


Link to post
Share on other sites
Doh... your right! ...Well, I did say I was "doodling", right?
lol

char * names [] = { "", ...ect.

---email--- Tok ----surf----
~The Feature Creep of the Family~

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!