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.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; }



LinkBack URL
About LinkBacks


