void random(int a[][4])
{
srand(time(NULL)); // if you call this function twice, you've seeded more then once.
int f[4]; //some badly named array of random ints from 0-6
int s[4]; //another one from 0-3
int c, b, i; // why is b and c necessary? and why i if it only exists within the scope of your for loop?
//I think local variables take presedence, so declaring i shouldn't be a problem as you don't use it anywhere outside of a for loop
// sum of random numbers
int sum = 0;
file2 << "4 Random Numbers " << "\n";
for( i = 0; i < 4; i++)
{
f[i] = rand() % 7;
s[i] = rand() % 4;
if((f[i] == 4) && (s[i] == 3)) // why can't f be 4 and s be 3?
{
b = rand() % 7;
c = rand() % 4;
// function that checks for duplicate random numbers
check(b, c, a); // what happens if it finds them? why do you need b and c?
}
elseif((f[i] == 5) && (s[i] == 2) || (f[i] == 5) && (s[i] == 3) ) // again
{
b = rand() % 7;
c = rand() % 4;
check(b, c, a); // x2
}
elseif((f[i] == 6) && (s[i] == 1) || (f[i] == 6) && (s[i] == 2) ||
(f[i] == 6) && (s[i] == 3)) // *cough*
{
b = rand() % 7;
c = rand() % 4;
check(b, c, a); // x3
}
else
{
file2 << a[f[i]][s[i]] << " "; // so dimension one is 0-6 at index i, and dimension two is 0-3 at index i, and index i is 0-3, a[0-6[0-3]][0-3[0-3]]
sum += a[f[i]][s[i]]; // i think the problem is here
//well what does the array a hold at these indexes?
}
}
file2 << "\n";
cout << "Sum " << sum;
file2 << "\n";
}
see if you can answer some of those, it'd help to know what the heck you're trying to accomplish.
also I just noticed, if this is the first run through then if f[0] is 4 and s[0] is 3, they remain undeclared, yet down there you use them as indexes, not good
but you aren't doing anything with b and c except checking if they are duplicates, if they aren't you display them, but you don't assign them to f or s, so imagine if i is 0, and it generates f[0] = 4 and s[0] = 3, now it gets stuck in that if statement which assigns b and c a new value, then checks if b and c are equal, if they are I still don't understand what it does, nothing? and if they aren't it outputs them to cout or a file.
the thing is, if f[0] = 4 and s[0] = 3 then none of the other else if checks will run, meaning it then skips to calculating f[1] and s[1] without assigning f[0] and s[0] with any value at all.
I don't understand what you mean by the conditions not containing any values.
as for the values of the array a, what are they exactly? that's a key part of it, its a two dimensional array, the first dimention is passed without limit and the second is passed with a limit of 4, is it even legal to do that? and then at the end you're looking for these values by using the random numbers as indexes for them.
Can I please see the code that assigns values to array a, the code for the check function, and any other function that the check function calls, along with an explanation of what you hope the sum will be and what the program is trying to do.
edit:
nevermind, they aren't unassigned, they just don't get added to the sum
I can't offer any because I don't know what you are trying to do
Can I please see the code that assigns values to array a, the code for the check function, and any other function that the check function calls, along with an explanation of what you hope the sum will be and what the program is trying to do.