Sorting & Comparing issues

I have a program that ask a user to input numbers and then a terminal value when finished. It calculates the sum of the numbers as well as count the positive, negative and zero numbers entered. However, I have to rewrite it to also determine what number was entered the most in a row. This is a lab assignment for college and I cant use arrays or read from files. My original code is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

    int num, sum, total_num, total_pos;
    int num1, num_comp2, num_row_count;
    int num_row_count2, num_row_count_pos;
    int total_neg, total_zero;
    char choice;
    
    do
    {
    
    //initialize counters
    sum=0;
    total_num=0;
    total_pos=0;
    total_neg=0;
    total_zero=0;
    num_row_count=1;
    
    cout<<"#################################################\n";
    cout<<"#                                               #\n";
    cout<<"# You will be asked to enter a number.          #\n";
    cout<<"# You may enter positive, negative or decimal   #\n";
    cout<<"# values including zero. The program will then  #\n";
    cout<<"# calculate the sum of the numbers and tabulate #\n";
    cout<<"# the types of numbers you entered.             #\n";
    cout<<"# When you are finished, enter 9999.            #\n";
    cout<<"#                                               #\n";
    cout<<"#################################################\n\n";
    cout<<"Please enter a number: ";
    cin>>num;
    
    while (num != 9999)
    { 
      if (num > 0)
      {  
             num1 = num;
             sum = sum + num;
             total_num++;
             total_pos++;
            
             
             while (num1 == num)
             {
                   
                   
                    cout<<"Enter another number: ";
                    cin>>num;
                    if (num == num1)
                    {
                            num_row_count++;
                            sum = sum + num;
                            total_num++;
                            total_pos++;
                    }
             }
             
             
      }
      
      else if (num < 0)
      {
           sum = sum + num;
           total_num++;
           total_neg++;
           cout<<"Enter another number. ";
           cin>>num;
      }
      
      else
      {
          total_num++;
          total_zero++;
          total_pos++;
          cout<<"Enter another number. ";
          cin>>num;
      }
    }
    
    //output of the data entered
    cout<<endl<<endl;
    cout<<"#################################################\n";
    cout<<"# Here is your breakdown:                       #\n";
    cout<<"#################################################\n";
    cout<<"#                                               #\n";
    cout<<"# Total numbers entered: "<<setw(22)<<total_num<<" #\n";
    cout<<"# Total positive numbers entered: "<<setw(13)<<total_pos<<" #\n";
    cout<<"# Total negative numbers entered: "<<setw(13)<<total_neg<<" #\n";
    cout<<"# Total zeros entered: "<<setw(24)<<total_zero<<" #\n";
    cout<<"# The sum of all numbers entered: "<<setw(13)<<sum<<" #\n";
    cout<<"#                                               #\n";
    cout<<"#################################################\n";
    cout<<"number in a row "<<num1<<endl;
    cout<<"number row amount "<<num_row_count<<endl;
    
    //menu option to continue or end program
    cout<<"\nWould you like to enter more numbers? (Y/N) ";
    cin>>choice;
    }while (choice=='y' || choice=='Y');
    return 0;
    
}


I am a little stumped at how to go about this. I have written a seperate program to isolate the counting of this, but as you can see, I am getting nowhere.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
using namespace std;

int main()
{
    int num, num2, sum, row_count, row_count2, count;
    sum=0;
    row_count=0;
    row_count2=0;
    count=0;
    
    cout<<"Enter a number ";
    cin>>num;
    num2 = num;
    
    while (num != 9999 || num2 != 9999)
    {
         if (num2 == num)
         {
             count++;
             sum=sum+num2;
             row_count++;
             row_count2=row_count;
             cout<<"Enter a number ";
             cin>>num2;
             if (num2 == 9999)
                break;
         }
                  
         else
         {
             count++;
             sum=sum+num2;
             row_count++;
             cout<<"Enter a number ";
             cin>>num;
             if (num == 9999)
                break;
         } 
    }
    
    cout<<"Sum is "<<sum<<endl;
    cout<<"Count is "<<count<<endl;
    cout<<"Row Count is "<<row_count2<<endl;
    
    system ("pause");
    return 0;


can anyone help me in the right direction? Thanks
If I understand you correctly, you want to get 7 if the input is 17772 but not 71727.
If so, then
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int num=0;
int rcount=0, rtype=0;
int rcountmax=0, rtypemax=0;

do{
    //Enter the num
    if(rtype == num) rcount++;
    else{
        if(rcount > rcountmax){
            rcountmax = rcount;
            rtypemax = rtype;
        }
        rcount = 0;
    }
    rtype = num;
}while(num != 9999);
//Write rtypemax and rcountmax+1 

though this code is a little wrong.
if you don't enter any repeating numbers it will return 0
if you, for example enter 00333 it will also return 0...
Thanks for the help. After looking at your suggestions and advice from someone else, I figured it out, for the most part. The program now works as I intended, but the only catch is when someone entered more than one number the same amount of times, it only catches the first one. For example if I entered: 55662210, It should say that 5, 6 and 2 were entered the most, but it displays 5. Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    //declare the variables
    double num, sum, total_num, total_pos;
    int total_neg, total_zero;
    double max_num, prev_num;
    int curr_count, max_count;
    char choice;
    
    do
    {
    
    //initialize counters
    sum=0;
    total_num=0;
    total_pos=0;
    total_neg=0;
    total_zero=0;
    
    //Display with instructions
    cout<<"#################################################\n";
    cout<<"#                                               #\n";
    cout<<"# You will be asked to enter a number.          #\n";
    cout<<"# You may enter positive, negative or decimal   #\n";
    cout<<"# values including zero. The program will then  #\n";
    cout<<"# calculate the sum of the numbers and tabulate #\n";
    cout<<"# the types of numbers you entered.             #\n";
    cout<<"# When you are finished, enter 9999.            #\n";
    cout<<"#                                               #\n";
    cout<<"#################################################\n\n";
    
    //Get input from user
    cout<<"Please enter a number: ";
    cin>>num;
    
    /*initialize counters & set variables for tracking 
    numbers entered consecutively and their value */
    max_num = num;
    max_count = 0;
    curr_count = 0;
    prev_num = max_num;
    
    //main section
    while (num != 9999)
    { 
      // Positive number sorting    
      if (num > 0)
      {  
             sum = sum + num;
             total_num++;
             total_pos++;
             
             //determines if numbers entered seqentially are the same
             if (num == prev_num)
             {
                  curr_count++;
          
          
                  if (curr_count > max_count)
                  {
                      max_count = curr_count;
                      max_num = num;
                      prev_num = num;
                      cout<<"Please enter a number: ";
                      cin>>num;
                  }
                  else
                  {
                      prev_num = num;
                      cout<<"Please enter a number: ";
                      cin>>num;
                  }
             }   
             else
             {
                 curr_count = 1;
                 prev_num = num;
                 cout<<"Please enter a number: ";
                 cin>>num;
             }
      }
      
      //Negative number sorting
      else if (num < 0)
      {
           sum = sum + num;
           total_num++;
           total_neg++;
           
           //determines if numbers entered seqentially are the same
           if (num == prev_num)
             {
                  curr_count++;
          
          
                  if (curr_count > max_count)
                  {
                      max_count = curr_count;
                      max_num = num;
                      prev_num = num;
                      cout<<"Please enter a number: ";
                      cin>>num;
                  }
                  else
                  {
                      prev_num = num;
                      cout<<"Please enter a number: ";
                      cin>>num;
                  }
             }   
             else
             {
                 curr_count = 1;
                 prev_num = num;
                 cout<<"Please enter a number: ";
                 cin>>num;
             }
      }
      
      //Zero sorting
      else
      {
          total_num++;
          total_zero++;
          total_pos++;
          
          //determines if numbers entered seqentially are the same
          if (num == prev_num)
             {
                  curr_count++;
          
          
                  if (curr_count > max_count)
                  {
                      max_count = curr_count;
                      max_num = num;
                      prev_num = num;
                      cout<<"Please enter a number: ";
                      cin>>num;
                  }
                  else
                  {
                      prev_num = num;
                      cout<<"Please enter a number: ";
                      cin>>num;
                  }
             }   
             else
             {
                 curr_count = 1;
                 prev_num = num;
                 cout<<"Please enter a number: ";
                 cin>>num;
             }
      }
    }
    
    //output of the data entered
    cout<<endl<<endl;
    cout<<"#################################################\n";
    cout<<"# Here is your breakdown:                       #\n";
    cout<<"#################################################\n";
    cout<<"#                                               #\n";
    cout<<"# Total numbers entered: "<<setw(22)<<total_num<<" #\n";
    cout<<"# Total positive numbers entered: "<<setw(13)<<total_pos<<" #\n";
    cout<<"# Total negative numbers entered: "<<setw(13)<<total_neg<<" #\n";
    cout<<"# Total zeros entered: "<<setw(24)<<total_zero<<" #\n";
    cout<<"# Number entered the most in a row: "<<setw(11)<<max_num<<" #\n";
    cout<<"# Number of times it was entered: "<<setw(13)<<max_count<<" #\n";
    cout<<"# The sum of all numbers entered: "<<setw(13)<<sum<<" #\n";
    cout<<"#                                               #\n";
    cout<<"#################################################\n";
    
    
    //menu option to continue or end program
    cout<<"\nWould you like to enter more numbers? (Y/N) ";
    cin>>choice;
    }while (choice=='y' || choice=='Y');
    return 0;
    
}


Thanks for the help.
Topic archived. No new replies allowed.