i need help and it's really urgent

Status
Not open for further replies.

Aravind Vijayan

Reputable
Jul 13, 2014
7
0
4,510
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
1,437
0
11,960
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
 

Aravind Vijayan

Reputable
Jul 13, 2014
7
0
4,510
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;
}
 
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

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

AtotehZ

Distinguished
Nov 23, 2008
403
13
18,815


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.
 

rgd1101

Don't
Moderator


because it said urgent :p , and it remind me of my first basic programming class.
 

AtotehZ

Distinguished
Nov 23, 2008
403
13
18,815


I'm considering to learn C++ myself, my dad needs a programmer for small jobs in his company, but asking questions about homework kinda pisses me off(I help people with math). Asking about the theory how it is used instead, then incorporating it into your work is more respectable.

If he wants help with programming he should go to a forums like:
Codeguru
Bytes
Codeproject
Programmers Heaven

Those are only the ones I know on the top of my head, but there are so many. If he asks about specific code and expect an exact solution to his homework there, he might just get banned.
 
Status
Not open for further replies.