Advertisement

i'm hitting a brick wall

Started by January 30, 2002 01:43 AM
3 comments, last by PWhermn 22 years, 10 months ago
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
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~
--------------------------~The Feature Creep of the Family~
Advertisement
Types should be char* names[]
...    
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Doh... your right! ...Well, I did say I was "doodling", right?
lol

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

---email--- Tok ----surf----
~The Feature Creep of the Family~
--------------------------~The Feature Creep of the Family~
Beware the language lawyer.

Edited by - Fruny on January 30, 2002 4:08:32 AM
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement