Finding percent error

1. Jul 13, 2010

magnifik

there are 1000 valid results, but 1 is invalid. in other words, 99.9% of the results are valid. what is the error rate for this to be possible?

basically right now i have these facts -- if A has more than B, A wins. in order for a result to be considered "valid," A must have more wins than B. below is a code with 15% error rate. my question is how do i find the error rate for the above restraints?

Code (Text):

int main(){
int A = 0;
int B = 0;
int aWins = 0;
int errorPercent = 15; // errorPercent% of the time, the comparison will be incorrect

srand(time(0));
for (int j = 0; j < 1000; j++){
for (int i = 0; i < 1000000; i++){
if ((rand()%2) == 0)
if( (rand()%100) + 1 > errorPercent )
B++;
else
A++;
else
if( (rand()%100) + 1 > errorPercent )
A++;
else
B++;
}
if (A > B)
aWins++;
}

2. Jul 14, 2010

Staff: Mentor

If you have 1000 valid results, then all one thousand of them are valid. There can't be any invalid results if all of them are valid results.

If you have 1000 results and one of them is invalid, then 99.9% of the results are valid.

What are you asking here? The only variable you have any control over is the errorPercent, so maybe you are supposed to try different values for this variable to see what happens.

You aren't being very clear on what you need to do, so if you want a better answer, you need to tell us exactly what problem you're trying to solve.

3. Jul 14, 2010

magnifik

i meant of the 1000 results, 999 are valid, 1 is invalid. that's the problem i'm having...the specs aren't very specific

4. Jul 14, 2010

Staff: Mentor

And your question isn't very clear. What's the problem you're trying to solve?

How do you know what result your program produces? There are no output statements.

5. Jul 14, 2010

magnifik

this is what i'm trying to do right now. i have it set up where 1000000 choose either A or B. the errorRate variable dictates whether or not the choices were swapped. i have it set up so the errorRate gets incremented until A is less than B (because A is supposed to be greater than B in this game). however, when i try to run it... it just prints 1000000000. when i try to enter the errorRate manually, A is finally less than B around the errorRate of 42. what am i doing wrong in my code??

Code (Text):

int errorRate = 0;
int A = 510000;
int B = 490000;
for (int z = 0; z < 1000; z++){
for (int x = 0; x < 1000000; x++){
if ((rand()%2) == 0){
if ((rand()%100) + 1 <= errorRate){
B--;
A++;
}
}
else{
if ((rand()%100) + 1 <= errorRate){
A--;
B++;
}
}
}
errorRate++;
if (A < B)
break;
}
cout << errorRate << endl;

6. Jul 15, 2010

Staff: Mentor

Each time the inner loop finishes an iteration, you increment errorRate (which starts at 0). By the time the outer loop is finished, errorRate will have been incremented to 1,000,000,000. No surprise there.

Instead of using errorRate as a glorified loop counter, I would suggest treating it as a constant that you set, and displaying something more useful, like A and B.