I'm getting unwanted output. It doesn't make sense. The output is either 0 new cars won or 1000 new cars one. Basically what I want to do is assign car, chosen, and revealed random values from 1 - 3. I have a do while loop so that revealed's value keeps getting changed if it is the same as the chosen value, once it isn't the same it should break the do while loop, and if the chosen value is the same as car's random value then it should increment the wins integer. Once it has looped through 1000 times wins should have a value of how many times chosen and car matched. The thing is it either outputs 0 wins or 1000 wins, which is obviously not right... Here is the code:
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int car = 0;
int chosen = 0;
int revealed = 0;
int wins = 0;
srand(time(NULL));
car = (rand() % 3 + 1);
chosen = (rand() % 3 + 1);
for (int i = 0; i < 1000; i++) {
do {
revealed = (rand() % 3 + 1);
} while (revealed == chosen);
if (chosen == car) {
wins++;
}
}
cout << "You won: " << wins << " new cars!";
cin.get();
}
By the way, in case you're wondering why I have a 'revealed' integer which at the moment has no visible purpose, it's because later on I'm going to be adding more code where it is vital :P
EDIT: NEVER MIND I'm an idiot, I wasn't even assigning new random values to the integers each pass through the loop, which explains the problem... Stupid mistake lol.