Jump to content

  • Log In with Google      Sign In   
  • Create Account


i'm hitting a brick wall


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 PWhermn   Members   -  Reputation: 122

Like
Likes
Like

Posted 29 January 2002 - 07:43 PM

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

Sponsor:

#2 Tok   Members   -  Reputation: 262

Like
Likes
Like

Posted 29 January 2002 - 08:23 PM

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~

#3 Fruny   Moderators   -  Reputation: 1653

Like
Likes
Like

Posted 29 January 2002 - 08:54 PM

Types should be char* names[]
...    


#4 Tok   Members   -  Reputation: 262

Like
Likes
Like

Posted 29 January 2002 - 09:02 PM

Doh... your right! ...Well, I did say I was "doodling", right?
lol

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

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

#5 Fruny   Moderators   -  Reputation: 1653

Like
Likes
Like

Posted 29 January 2002 - 09:07 PM

Beware the language lawyer.

Edited by - Fruny on January 30, 2002 4:08:32 AM




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS