Archived

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

PWhermn

i'm hitting a brick wall

Recommended Posts

PWhermn    122
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
Tok    262
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
Tok    262
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