Hello fellow programmers, I decided to make a hit counter. Basically its an array that loops through the first and last index. In that loop I have a random number generator which will increase the value at that index by 1.
/*HitCounter.cpp By JacobAmaral*/
#include "stdafx.h"
#include "iostream"
#include "stdlib.h"
using std::cout; using std::cin; using std::endl;using std::rand;
/*Main method*/
void _tmain(int argc, _TCHAR* argv[])
{
int randNum;
int hitCounter[100];
for (auto i = 0; i != 100; i++)
{
hitCounter[rand() % 100]++;
}
cout << "Position\t Hits" << endl;
for (int n = 0; n != 100; n++)
{
cout << n << "\t\t" << hitCounter[n] << endl;
}
I made this program in Java but obviously C++ has differences. The problem is I am getting very odd values (-8789655), some of the value are different and some are the same. Its not counting hits the way I want it to be (positive).