| | |
Please help about USER INPUT
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 22
Reputation:
Solved Threads: 0
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
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
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
c Syntax (Toggle Plain Text)
#include<iostream.h> int main() { int num,temp; cin>>num; if (num < 1000 || num > 3000) { cout<<"invalid"; else { temp=num/1000; num=num%1000; switch(temp) { 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.
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?
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.
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?
Got it?
-->sometimes i wanna take my toaster in a bath<-- 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...
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...)
i've seen you've worked out part of the solution... so, here's what you might want to do...
c Syntax (Toggle Plain Text)
case 1: cout<<"one thousand"; break; case 2: cout<<"two thousand"; break; case 3: ...
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<-- ![]() |
Similar Threads
- user input into a string (C++)
- Tutorial: User Input: Strings and Numbers [C] (C)
- Handling Invalid User Input? (C)
- inline assembly getting user input.(djgpp) (Assembly)
- Type Conversion of User Input: (C++)
- Error Checking for user input (Java)
- error checking of user input (C++)
- Creating a GUI that accepts user input help (Java)
- Need Help With Error Checking User Input (C)
- filtering bad user input (Java)
Other Threads in the C++ Forum
- Previous Thread: C++ break and continue statements
- Next Thread: I need help writing a program using Fibonacci sequence
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






