• 06-15-2003
absi
I tried to solve the program for a look and read digit. The user input a number like 488667 and the result of the program should be 14282617 with no function,array, or pointer used. To solve the program I get an error which is that the counter does not cumulate.Please if somebody have any suggestions I would appreciate it.

Code:

``` #include <iostream> #include <math.h> using namespace std; int main() {                 int m,c,i,n;         int counter=0;         cout<<endl<<endl;         cout<<"    Please enter number"<<endl;         cin>>n;         int s =log10(n);                 for(i=s;i>=0;i--)         {                                         c=pow(10,i);                         m=(pow(10,(s-i)));                         if(((n/(c))%10)==((n/(c/10))%10))                 {                                         counter+=1;                                                 }                                 cout<<counter<<(n/c)%10;                 if(((n/(c))%10)!=((n/(c/10))%10))                         cout<<"1"<<(n/c)%10;                                                                 }                                        return 0; }```
Thanks.
• 06-15-2003
kuphryn
I recommend long data type instead of int. As for the algorithm, you designed it, so debug it.

Kuphryn
• 06-15-2003
Zach L.
One thing... I'd advise using <cmath> instead of <math.h>. The former is a member of the standard library, and encapsulates its members in the std namespace. Aside from that, what is your algorithm supposed to be doing?
• 06-15-2003
Absi
Zach; the algorithm is that if the first number is the same as the number after it( repeated number) I should see how many times it reapeats it self and then print the number of times and the number itself if not just print out number 1 and the number itself.
for example when I input the number 7488999 the secreen should show 17142839 i.e look and read . As for "kuphryn"
please if you do not want to help just do not, I know it is my code but if I'm able to debug it I would not post it and I think this forum is to offer help and information exchange it.Thanks
• 06-15-2003
HaLCy0n
I got bored, so I tried my hand at this quick. Unless you plan on doing some actual math with these numbers, its easier to handle it as a string.
Code:

```#include <iostream> #include <string> using std::cout; using std::cin; using std::string; using std::endl;                                                                                 int main() {     string input;                                                                                     cout << "Please input a number: ";     cin >> input;                                                                                     int size=input.size();     int count=1;     for(int x=0;x<size-1;++x)     {         if(input[x]==input[x+1])             count++;         else         {             cout << count << input[x];             count=1;         }     }     cout << count << input[size-1]; }```
It should work fine I believe.
• 06-15-2003
Nubi
but if you are looking to do math with it...

use the modulus '%'

and with a few for loops and such you should have your answer.
• 06-16-2003
absi
Thanks guys, yeh.. I should do the math no string allowed yet. I did used the Mod but my problem was with counter and I found out the reason why it is not accumulating because it was not reading the next digit right. Thank you very much any way for the help...I appreciate it.