Need the output to back again

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:

Code:

#include<iostream>

#include <climits>

using namespace std;

int main (){

unsigned long int num,temp2,

n,count,diviser,digit,i,counter,temp1,base;

n=1;

cout<<"Please enter the number :"<<endl; //getting input

cin>>num;

temp1=num;

count=0;

while (temp1!=0){ //counting number of digits

temp1=temp1/10;

count=count+1;

}

cout<<"The look-and-say value of the given number is :";

i=1;

temp2=0;

counter=1;

count=count+1;

base=1;

for(int r=1;r<=count;r++){ // to get the power of 10

base=base*10;

}

diviser=base;

for (i=1; i<=count;i++) { //seperating each digit

//and printing output

diviser=(diviser/10);

digit=num/diviser;

if (i> 2){

if(temp2==digit)

counter++;

else {

cout<<counter<<temp2;

counter=1;

}

}

temp2=digit;

num=num%diviser;

}

cout<<counter<<temp2;//this to show the last digit

cout<<endl;

return 0;

}

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.

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

Code:

`#include<iostream>`

#include <climits>

using namespace std;

int main (){

unsigned long int num,temp2,

n,count,diviser,digit,i,counter,temp1,base;

n=1;

cout<<"Please enter the number :"<<endl; //getting input

cin>>num;

temp1=num;

count=0;

while (temp1!=0){ //counting number of digits

temp1/=10;

count++;

}

cout<<"The look-and-say value of the given number is :";

i=1;

temp2=0;

counter=1;

count++;

base=1;

for(int r=1;r<=count;r++){ // to get the power of 10

base*=10;

}

diviser=base;

for (i=1; i<=count;i++) { //seperating each digit

//and printing output

diviser/=10;

digit=num/diviser;

if (i> 2){

if(temp2==digit)

counter++;

else {

cout<<counter<<temp2;

counter=1;

}

}

temp2=digit;

num%=diviser;

}

//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?