/*#include <fstream>
#include <iostream>
using namespace std;
//uses loop to randomly generate value into each element of array
double genValues(double* dblArray)
{
int i;
for (i = 0; i < 100; i++)
dblArray[i] = (rand() % 50 + 1);
}
//counts how many a times a number is stored in array and prints our for each //number
double countValues(double* dblArray)
{
int i;
int addValue = 0;
for (i = 0; i < 100; i++)
if (dblArray[i] == (rand() % 50 + 1))
{
addValue++;
cout<< dblArray[i] << "repeats itself "<<addValue<<" times."<<endl;
}
//return addValue;
}
int main()
{
double* dblArray[100];
genValues(dblArray[100]);
countValues(dblArray[100]);
return 0;
}*/
2) line 34 makes an array of pointers, not an array of doubles. Assuming you want an array of doubles, use double dblArray[100]; instead
3) why are you using doubles for this array? rand returns an integer, and you shouldn't use == with doubles anyway becaues doubles are an approximation.
4) lines 36 and 38 go out of bounds on the 'dblArray' array. If you make an array of 100 elements, then only elements 0-99 are valid. When passing a pointer to the array as a function parameter, leave out the brakets: genValues( dblArray ); // note, no [brakets]
5) Your genValues function has a 'double' return type, but doesn't return anything (your compiler should be erroring at you). Either return something, or change it to a void.
6) Ditto for countValues, although it looks like you might want countValues to return an int (not a double).
Wow, thanks. Actually almost working now, but the program always outputs the same answer when it should always be different because of rand. you guys have any idea why because everything seems to be right to me.
Wow can't believe i missed that key thing, must not be my day. Everything is working now, but my teacher still says it's wrong do you guys see anything i'm missing?
because it seems sometimes it gives me a cout message that is the same as previous one.