Please help about USER INPUT

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 22
Reputation: jenymaru08 is an unknown quantity at this point 
Solved Threads: 0
jenymaru08 jenymaru08 is offline Offline
Newbie Poster

Please help about USER INPUT

 
1
  #1
Apr 28th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,047
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Please help about USER INPUT

 
2
  #2
Apr 28th, 2007
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.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 30
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: Please help about USER INPUT

 
0
  #3
Apr 28th, 2007
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?
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,663
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 725
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Please help about USER INPUT

 
0
  #4
Apr 28th, 2007
>Got it?
Please. With that kind of explanation, even I wouldn't get it.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 30
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: Please help about USER INPUT

 
0
  #5
Apr 28th, 2007
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...)
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC