### hi..i need some help here..

convert a positive integer code into its english name equivalent for digit. A valid code is of size between four (4) to six (6) digits inclusive. A zero is not allowed in the code.

example : if the input is 234056 the output is : INVALID CODE (PRESENCE OF ZERO)
if the input is 23456 the output is : TWO THREE FOUR FIVE SIX
if the input is 9349 the output is : NINE THREE FOUR NINE
if the input is 245 the output is : INVALID CODE (3 DIGITS)
if the input is 2344567 the output is : INVALID CODE (7 DIGITS)
This is pretty straight forward. You're lucky you only have to worry about writing the English words for digits, and not for the whole number.

You can check if a number has between four and six digits inclusive like so:

if((number > 999) && (number < 1000000)) {
You can then convert the number to a string, and iterate through the string elements (digits) using a simple loop.
Then, it's just a matter of printing out the words (I recommend an array of strings), and some small error checking to see if the number contains a zero.
Yeah that's pretty cool!

Aceix.
i still no get it...

the question give me a step to follow..please show me how write it..
this is the step given :

step 1 : input code
step 2 : count the number of digits in the code
step 3 : if there is a zero in the code, "INVALID CODE (PRESENCE OF ZERO)" go to step 4
step 4 : if number of digits is mode or equal than 4 and less or equal than 6, go to step 5 else display the following message "INVALID CODE (<number of digits> DIGITS)
step 5 : call a function called digit_name to convert each digit into its
equivalent english name. display the result
step 6 : print the digits in reverse order
eg; if input is 13453, reverse order is 35431

my lecture only teach <iostream>..please show the write using <iostream>
Last edited on
-Get the input into a string type or array of char
-first iterate through for the presence of a zero
-iterate though once more to convert to words br comparing against some constants
-print out the words

Aceix.
I only can do until this:

#include <iostream>
using namespace std;
int main ()
{
int code;
int count=0;
int k,m;
int A[10];

cout<<"key-in the code : ";
cin>>code;

k=code;
while (k)
{
count++;
k=k/10;
m=count;

}
cout<<"total digit of code : "<<m<<endl;

A[10]=code;
cout<<"A : "<<A[10]<<endl;

return 0;
}

 123456789 const string n1="one", n2="two",n3="three",...; char num[]='2','1','3'; for(int i=0;i<3;i++) { if(num[i]=='2') cout<

Blah........
That's the general overview of one way you can go about it.

Aceix.
how to do this using loop?

#include <iostream>
using namespace std;
int main ()
{
int quotient,reminder,sum;
int k;

cout<<"key-in 3 integers positive : ";
cin>>k;

reminder=k;
quotient=reminder/100;
reminder=reminder%100;
sum=sum+quotient;
cout<<"quotient : "<<quotient;

quotient=reminder/10;
reminder=reminder%10;
sum=sum+quotient;
cout<<" + "<<quotient;

quotient=reminder/1;
reminder=reminder%1;
sum=sum+quotient;
cout<<" + "<<quotient<<endl;

cout<<"total sum of quotient : "<<sum<<endl;

return 0;

}
Has your master introduced you to C++ style strings? ie the string class?

Aceix.
Hello, can somebody help me with this? I need to print this thing:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
hi there..
for my problem..i try to solve it..but i'm stuck now...i'm really hope you guys can help me..my submission date will be this thursday...here my job...i don't know its correct or not...

#include <iostream>
using namespace std;
int main ()
{
int code;
int count=0;
int k,l,m,n,o;
int A[10];
int q,r;
int h,i,j;

cout<<"key-in the code : ";
cin>>code;

l=1;
k=code;
while (k)
{
count++;
k=k/10;
l=l*10;
m=count;

}
cout<<"total digit of code : "<<m<<endl;
cout<<"result m : "<<l<<endl;

for (i=0;i<=9;i++)
A[i]=0;
i=0;
q=code;
n=l;

while (q!=0)
{
r=q;
n=n/10;
q=r/10;
r=r%10;
A[i]=r;
i=i+1;

}
for (j=i-1;j>=0;j--)

cout<<""<<A[j];

if (m<=3)
cout<<"INVALID CODE ("<<m<<" DIGITS)"<<endl;
else if (m>6)
cout<<"INVALID CODE ("<<m<<" DIGITS)"<<endl;

return 0;
}
Topic archived. No new replies allowed.