i need help and it's really urgent

Aravind Vijayan

Estimable
Jul 13, 2014
7
0
4,510
0
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)

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
 

Scremin34Egl

Honorable
Nov 13, 2013
3
0
10,510
0
I did java a long time ago and i'm sure this is not the same language but to reverse the digits you would:

read in digits as a string
run a loop backwards (start at max length (make sure the digits are a string), and -1 from length)
combine the chars into a string
convert back to integer if necessary
 
We don't really like answering homework questions; it stops you learning and is something of a waste of time.

You'll want if-elseif-else constructs. Treat the number as a string.

Depending on what language you're writing in, there might be a 'reverse string' function.
 

Aravind Vijayan

Estimable
Jul 13, 2014
7
0
4,510
0
C++:
#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=0;
    
    i=0;
    q=code;
    n=l;
    
    while (q!=0)
    {
        r=q;
        n=n/10;
        q=r/10;
        r=r%10;
        A=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;
}
 

Scremin34Egl

Honorable
Nov 13, 2013
3
0
10,510
0


I have no idea what language that is, I only did a basic course in java.

I bet you'll have better luck on a programming forum, try dreamincode, http://
 

Ijack

Distinguished
You've given us a specification.
You've given us some (rather poorly written) code.
But you haven't actually asked a question.

What exactly are you seeking from us, and why are you discussing it on an Internet forum rather than discussing it with your teacher?
 

randomizer

Distinguished
Jul 24, 2006
880
0
19,260
62
I have attempted to format the code a bit better with a terrible online beautifier, hopefully without altering the logic (I probably have though... I fear loops with no braces). I've also added syntax highlighting for your viewing pleasure.

Aravind, please paste any code between code tags (eg. [ code="cpp" ]CODE GOES HERE[/code] but without spaces inside the brackets). That way we can read it, and I won't have to reformat it and run the risk of altering the logic :)

Also, tell your teacher that using variables like "r", "q" and "h" isn't very helpful for understanding what is going on.
 

rgd1101

Don't
Moderator
the program works but mr sir told me my coding is wrong ..... and i still no idea how else to do it .....
Just because it compile doesn't mean it correct
missing step 3
missing step 5

Do you see the IF xxxx go to step x
you are not doing that.

bunch of codes that does nothing for the problem
 

AtotehZ

Distinguished
Nov 23, 2008
23
0
18,560
0


I'm astounded by the amount of replies you got to this thread. You gave a useless topic title and didn't ask a question.

The answers per view is mind boggling.
 

ASK THE COMMUNITY