HELp me

Pages: 12
Excuse meee Plss can you help me about converting Numbers to words like for example

if the user input 1
it print ONE

1-3000 is the maximum number it can convert

using Switch TNX need help ASAP
So have you noticed any patterns in the words?
Hmmm patterns?? i dont notice any butttt i see the code here but its broken
Here salem in this link a code from supernal
http://www.cplusplus.com/forum/general/71840/

That kind of code
but its not perfect when i check forums
pls help me
Yeah, that's close enough.

Try to figure out what's wrong with it and fix it.

> Hmmm patterns?? i dont notice any
You don't?

Outside of 1 to 20, everything is regular

21 - twenty one
31 - thirty one
41 - forty one

121 - one hundred and twenty one
131 - one hundred and thirty one
141 - one hundred and forty one

1121 - one thousand, one hundred and twenty one
1131 - one thousand, one hundred and thirty one
1141 - one thousand, one hundred and forty one

can you help me ??
can you helpp me to understand the code in the link ?
Yes, but you'll have to tell us what you don't understand about it. Have you used switch statements before? Have you used cout << before? What about %? That's about all there is to the code.
You should notice that with 10 numbers (0-9) you can make every possible number. So if you know the position of the number (10s, 100s, 1000s place), you can know the format you'll output the number along with the individual digits.

After just looking at the code in the link, it's fairly straight forward. You seem to not be very familiar with coding and/or switch statements. Since the problem you've presented is pretty simple to solve, I'll assume you haven't coded much but you're expected to output results. It's important to put the time in to code.

http://learncpp.com
I know about the cout
I know about switch but a little

my problem is i dont understand the flow

in the code in the link

the user input number right ? i understand the cin process

but the thing that confuse me is the % modulus?? yeah i dont know how it works

pls make me understand and finish it
Tnx alot pls help me
zapshe i go with the link you send.. What part there that can give me explanantion in the problem??
tnx
thousands=(num/1000)%10;
hundreds=((num/100)%100)%10;
tens=(num/10)%10;
ones=num%10;

this part hahahaha


so if i input 1 then num =1

and all of that have a value because num have a value
but the thing that confuse me is how the code know that i input tens Maybe you can understand the code now but me im confuse
i try to know the values of thousands to ones

if i input 1

and only one get the value of 1 and else got 0

is that how the switch know when and what to cout ?????
Try posting your code so far.

#include <iostream>
#include <conio.h>

using namespace std;

main(){
int num, ones, tens, hundreds, thousands;

cout<<"Enter a digit from 1-3000: ";
cin>>num;

thousands=(num/1000)%10;
hundreds=((num/100)%100)%10;
tens=(num/10)%10;
ones=num%10;

switch(thousands){

case 1:
cout<<"One Thousand ";
break;
case 2:
cout<<"Two Thousand ";
break;
case 3:
cout<<"Three Thousand ";
break;
}

switch (hundreds){
case 1:
cout<<"One Hundred ";
break;
case 2:
cout<<"Two Hundred ";
break;
case 3:
cout<<"Three Hundred ";
break;
case 4:
cout<<"Four Hundred ";
break;
case 5:
cout<<"Five Hundred ";
break;
case 6:
cout<<"Six Hundred ";
break;
case 7:
cout<<"Seven Hundred ";
break;
case 8:
cout<<"Eight Hundred ";
break;
case 9:
cout<<"Nine Hundred ";
break;
}



switch (tens){

case 1:
switch (ones)
{



case 1:
cout<<"eleven ";
break;
case 2:
cout<<"twelve ";
break;
case 3:
cout<<"thirteen ";
break;
case 4:
cout<<"Fourteen ";
break;
case 5:
cout<<"Fifteen ";
break;
case 6:
cout<<"Sixteen ";
break;
case 7:
cout<<"Seventeen ";
break;
case 8:
cout<<"Eighteen ";
break;
case 9:
cout<<"Nineteen ";
break;
}
case 2:

cout<<"Twenty ";
break;
case 3:
cout<<"Thirty ";
break;
case 4:
cout<<"Fourty ";
break;
case 5:
cout<<"Fifty ";
break;
case 6:
cout<<"Sixty ";
break;
case 7:
cout<<"Seventy ";
break;
case 8:
cout<<"Eighty ";
break;
case 9:
cout<<"Ninety ";
break;
}

switch (ones){
case 1:
cout<<"One ";
break;
case 2:
cout<<"Two ";
break;
case 3:
cout<<"Three ";
break;
case 4:
cout<<"Four ";
break;
case 5:
cout<<"Five ";
break;
case 6:
cout<<"Six ";
break;
case 7:
cout<<"Seven ";
break;
case 8:
cout<<"Eight ";
break;
case 9:
cout<<"Nine ";
break;
}
getch();
}

theeeeeeee the problem on the code in the link is about teen numbers like fourteen and so on and also eleven and 12

so i try to put a case 1 in the tens

i ll manage to get the teen numbers but still cout the other words like

input 12

print

twelve twenty 2
OWKKKKKK ill fixx the teen problem

it doesnt print the word twenty two anymore

I just put goto so it jump the process
then return 0





#include <iostream>


using namespace std;

main(){
int num, ones, tens, hundreds, thousands;

cout<<"Enter a digit from 1-3000: ";
cin>>num;

thousands=(num/1000)%10;
hundreds=((num/100)%100)%10;
tens=(num/10)%10;
ones=num%10;

switch(thousands){

case 1:
cout<<"One Thousand ";
break;
case 2:
cout<<"Two Thousand ";
break;
case 3:
cout<<"Three Thousand ";
break;
}

switch (hundreds){
case 1:
cout<<"One Hundred ";
break;
case 2:
cout<<"Two Hundred ";
break;
case 3:
cout<<"Three Hundred ";
break;
case 4:
cout<<"Four Hundred ";
break;
case 5:
cout<<"Five Hundred ";
break;
case 6:
cout<<"Six Hundred ";
break;
case 7:
cout<<"Seven Hundred ";
break;
case 8:
cout<<"Eight Hundred ";
break;
case 9:
cout<<"Nine Hundred ";
break;
}



switch (tens){

case 1:
switch (ones)
{



case 1:
cout<<"eleven ";

goto b;
break;
case 2:
cout<<"twelve ";
goto b;
break;


case 3:
cout<<"thirteen ";
goto b;
break;
case 4:
cout<<"Fourteen ";
goto b;
break;
case 5:
cout<<"Fifteen ";
goto b;
break;
case 6:
cout<<"Sixteen ";
goto b;
break;
case 7:
cout<<"Seventeen ";
goto b;
break;
case 8:
cout<<"Eighteen ";
goto b;
break;
case 9:
cout<<"Nineteen ";
goto b;
break;
}
case 2:

cout<<"Twenty ";
break;
case 3:
cout<<"Thirty ";
break;
case 4:
cout<<"Fourty ";
break;
case 5:
cout<<"Fifty ";
break;
case 6:
cout<<"Sixty ";
break;
case 7:
cout<<"Seventy ";
break;
case 8:
cout<<"Eighty ";
break;
case 9:
cout<<"Ninety ";
break;
}

switch (ones){
case 1:
cout<<"One ";
break;
case 2:
cout<<"Two ";
break;
case 3:
cout<<"Three ";
break;
case 4:
cout<<"Four ";
break;
case 5:
cout<<"Five ";
break;
case 6:
cout<<"Six ";
break;
case 7:
cout<<"Seven ";
break;
case 8:
cout<<"Eight ";
break;
case 9:
cout<<"Nine ";
break;
}

b:

return 0;
}



MY PROBLEM NOW IS THE LIMIT OF 3000

WHEN I PUT 3001 IT STILL CONVERT IT

AND WHEN I PUT 30001

IT PRINT 1

PLS HELP ME PUT A LIMIT
I try to put

this
before the switch statement

if (1<=num<=3000)

but it doesnt work

even i put 3001

Pages: 12