- #1
Demon117
- 165
- 1
This is the code I have:
Why does my mode keep coming back for i?
Code:
#include <iostream>
#include <cstring>
using namespace std;
template <class X> X mode(X *data, int size)
{
register int t, w;
X md, oldmd;
int count, oldcount;
oldmd = 0;
oldcount = 0;
for(t=0; t<size; t++) {
md = data[t];
count = 1;
for(w = t+1; w < size; w++)
if(md==data[w]) count++;
if(count > oldcount) {
oldmd = md;
oldcount = count;
}
}
system("pause");
return oldmd;
}
int main()
{
int i[] = { 2, 3, 4, 2, 1, 2, 2, 5, 6, 7};
char *p = "lame question";
cout << "mode of i: " << mode(i, 100) << endl;
cout << "mode of p: " << mode(p, (int) strlen(p))<<endl;
system("pause");
return 0;
}
Why does my mode keep coming back for i?