i need help and it's really urgent

Aravind Vijayan

Estimable
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

rgd1101

Don't
Moderator
maybe you shouldn't be taking programming class.

Scremin34Egl

Honorable
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

USAFRet

Illustrious
Moderator
What code have you tried that doesn't work?

Someone Somewhere

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

USAFRet

Illustrious
Moderator
What language is this supposed to be in?

Aravind Vijayan

Estimable
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;
}``````

Aravind Vijayan

Estimable
this is what my sir gave... and i still have no clue

USAFRet

Illustrious
Moderator
OK, so now you have a block of code. Run it. Where and how does it fail?

This is called 'debugging'.

Scremin34Egl

Honorable

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?

Aravind Vijayan

Estimable
this is introduction to c++

Aravind Vijayan

Estimable
the program works but mr sir told me my coding is wrong ..... and i still no idea how else to do it .....

Someone Somewhere

Splendid
Comment and indent. If the code works correctly, that's bound to be it.

randomizer

Distinguished
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

Aravind Vijayan

Estimable
so what should i do ??

Ijack

Distinguished
You could always try discussing this with your teacher.

rgd1101

Don't
Moderator

read the requirement and see what you miss. or like the other said talk to your teacher because he will need to explain it to you.

AtotehZ

Distinguished

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.