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