I made a function that give the value of any number like the way you read it. For example you have the number "144566" the out put of the function will be printed to the secreen as follows:11241526
and the function is as follows:

Now what I need is to make the output of that function goes back again so the function read it again as many times as I want.My problem is that the output of that function is printed to the screen as and is not saved into variable because I can not save it for being an output to the screen that changes with the loop. I'm not allowed to use the string liberary. If you want to understand what I mean just run the function and what I want is to make the output of the function to go back again in the same function and no recursive is allowed yet. Please if any idea or help I would appreciate it.

06-23-2003

confuted

Re: Need the output to back again

Quote:

Originally posted by Alabsi I made a function that give the value of any number like the way you read it. For example you have the number "144566" the out put of the function will be printed to the secreen as follows:11241526

That, in no way, makes any sense, whatsoever. Could you explain that?

Some tips (shorthand, basically)

instead of count=count+1; do count++; It does the same thing.
instead of temp1=temp1/10; do temp1/=10 it does the same thing too
instead of base=base*10 do base*=10 (same thing again)
I'll edit your code to reflect this so you can see what I mean...it's just a shorter and clearer way of writing things

}
//no need to make two calls to cout, just stick endl on the first
cout<<counter<<temp2<<endl;//this to show the last digit

return 0;

}

As for what that's supposed to do... you lost me. Could you clarify?

06-23-2003

ygfperson

144566

11241526
one '1', two '4's, one '5', two '6's

Just parse out all the digits of the number and sort them. Then read them back the way you want.

06-23-2003

Alabsi

Look and say

ygfperson got it exactly right, this function just out put the number the same way you read it, just run it and put any number and you will see what I mean like you put this number 22488 the output will look 221428, what I want now from this function is just to input the privious output as current input that the number we have just saw as output which is 221428 will be input and its output will be 2211141218 and so on as much as I want. Thanks and waiting for any suggestions and Idea and my problem is how to save every output and put it back in the function.just remember no string or recursion are allowed yet, arrays are O.K.

06-24-2003

Cat

I don't know how you read numbers, but I read 22488 as "twenty-two thousand four hundred and eighty-eight".

That said, put your code into a function that takes the int as a parameter and returns the converted int. You can put it into a loop which aska if you want to continue.

06-24-2003

Alabsi

Look and read

Cat.. I do not want to read the number as a whole like 3314 ... how many 3s are there.. 2 right? so we say 23and how many 1s there is only one 1 so we print 11 and so on so the total number is 231114 , I hope this is clear. Now you want me to put the output back into the function and this is my problem is how to save the output into a variable so I can pass it back into the function because I do not just want to loop the same function but I want to loop the output...please if you can help with idea thanks.

06-24-2003

Hammer

>>pass it back into the function

Code:

int foo(int input)
{
int NewNumber;

// Do work here

return NewNumber;
}

Is that what you mean?

06-24-2003

Alabsi

Look and say

I hope that I can put my out put into variable so I can return it back. The problem is that my output is printed to the screen one at a time without being saved in a variable and I'm trying to save it in a variable but I'm out of hope this is my main question. If I coud put the "cout<<counter<<temp2" in a variable then my problem is solved. I can put it back easy to the same function I do not have problem with that......I hope I'm clear now and thank you for the help....