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

#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

Comments
thanks for using code tags

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?

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?

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...

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...)

This article has been dead for over six months. Start a new discussion instead.