944,142 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1049
  • C++ RSS
Apr 28th, 2007
1

Please help about USER INPUT

Expand Post »
Elow, I'm new member of this forum and also new in C++.I'm just start to learn it

I need help.....i want to write a program that will ask the use an integer number and output the word equivalent ofthe input(1000-3000)limit inclusive

example

input:1525
output: one thousand five hundred twenty-five

i will use a CONDITION STATEMENT but I;mconfuse with the CASE how willyou know if you will use CASE 1 Up to CASE 9
  1. #include<iostream.h>
  2.  
  3. int main()
  4. {
  5. int num,temp;
  6. cin>>num;
  7.  
  8. if (num < 1000 || num > 3000)
  9. {
  10. cout<<"invalid";
  11. else
  12. {
  13. temp=num/1000;
  14. num=num%1000;
  15. switch(temp)
  16. {
  17. case 1:cout<<"one thousand";

i dont know if I'm writing the right CODE, Please help i really dont have any idea about how will your ouput be in words


please help

thanks
Last edited by WolfPack; Apr 28th, 2007 at 10:03 am.
Similar Threads
Reputation Points: 21
Solved Threads: 0
Newbie Poster
jenymaru08 is offline Offline
22 posts
since Apr 2007
Apr 28th, 2007
2

Re: Please help about USER INPUT

This is certainly a non-trivial problem for somebody with your amount of experience.

Here's one tool I recommend using in the function, to make your time easier. Make an array or a vector which contains the numbers in string form, from "one" to "nineteen". I'm not sure what experience you have with C++, and whether you know how to use arrays or vectors, or about your knowledge of the string class, so I'll balk at a code example.

Make another array (or vector) that contains the names "twenty" through "ninety", too. With these, you won't need so many case statements. You won't need any, in fact.

Generally speaking, the strategy for this should be something like the following:

1. print out thousands part of the number
2. print out the hundreds part of the number
3. If the two-digit part is less than twenty, print out the name of the number. Otherwise, print out the name of the tens part, and then, if the units digit is nonzero, print out the hyphen and the units part name.

I don't understand your actual question, though. What don't you understand about switches and the case syntax?
Last edited by Rashakil Fol; Apr 28th, 2007 at 9:28 pm.
Team Colleague
Reputation Points: 1135
Solved Threads: 173
Super Senior Demiposter
Rashakil Fol is offline Offline
2,479 posts
since Jun 2005
Apr 28th, 2007
0

Re: Please help about USER INPUT

i will take my guess, and say you have low or no experience at all with c++... so... here's the deal... when you develop a switch, you write the code you want the program to run through in every case, and after every case, you write a break;, which will end the switch decision, and continue with the next part of the program...

Got it?
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007
Apr 28th, 2007
0

Re: Please help about USER INPUT

>Got it?
Please. With that kind of explanation, even I wouldn't get it.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Apr 28th, 2007
0

Re: Please help about USER INPUT

lol... ok... here's more specific ok?

i've seen you've worked out part of the solution... so, here's what you might want to do...

  1. case 1:
  2. cout<<"one thousand";
  3. break;
  4. case 2:
  5. cout<<"two thousand";
  6. break;
  7. case 3:
  8. ...

by the way, i have a suggestion to make... why don't you better print only the quantity of thousands there are in the number, and, after the switch is finished you print "thousand"... (you should want to do the same thing with million, hundreds, etc...)
Featured Poster
Reputation Points: 424
Solved Threads: 57
Posting Virtuoso
Nichito is offline Offline
1,594 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ break and continue statements
Next Thread in C++ Forum Timeline: 1%2 ? what is the answer ???





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC