Hello, total programming noob here. I really enjoyed making the C++ triple X game although mine was based on a plump kid trying to get into a fridge at fat camp (my failed attempts at dieting may have played a part here…). Anyway, having got to the random number generator, I thought it would be fun make a Lottery Number “predictor” (obviously it doesn’t predict anything) based on the same method.
It’s based on the UK lottery which has 6 balls numbered 1 - 59 (although for testing I’ve made it 1-6 so I can see if it’s repeating numbers). I can get 6 balls easily enough, but obviously once a ball is taken it can’t be used again. For example, if ball 1 is 11, no other ball should be 11. How do I exclude numbers that have already been generated for the previous ball? Any help is greatly appreciated. Code below:
#include <iostream>
#include <ctime>
void PrintIntroduction()
{
//Print welcome messages to terminal
std::cout << "\n\nHello, Welcome to Dave's Totally Accurate National Lottery Number Predictor, with is guaranteed to make you a millionaire*\n";
std::cout << "*Guarantee not actually guaranteed, millionire chances incredibly small, you're daft as a brush is you believe this guff\n";
}
int main()
{
PrintIntroduction();
/* initialize random seed: */
srand (time(NULL));
//declare 6 balls
const int Ball1 = rand() % 6 + 1;
const int Ball2 = rand() % 6 + 1;
if (Ball2 == Ball1);
{
const int Ball2 = rand() % 6 + 1;
}
const int Ball3 = rand() % 6 + 1;
if (Ball3 == Ball1 || Ball2);
{
const int Ball3 = rand() % 6 + 1;
}
const int Ball4 = rand() % 6 + 1;
if (Ball4 == Ball1 || Ball2 || Ball3);
{
const int Ball4 = rand() % 6 + 1;
}
const int Ball5 = rand() % 6 + 1;
if (Ball5 == Ball1 || Ball2 || Ball3 || Ball4);
{
const int Ball5 = rand() % 6 + 1;
}
const int Ball6 = rand() % 6 + 1;
if (Ball6 == Ball1 || Ball2 || Ball3 || Ball4 || Ball5);
{
const int Ball6 = rand() % 6 + 1;
}
std::cout << "Ball 1\n";
std::cout << Ball1;
std::cout << "\nBall 2\n";
std::cout << Ball2;
std::cout << "\nBall 3\n";
std::cout << Ball3;
std::cout << "\nBall 4\n";
std::cout << Ball4;
std::cout << "\nBall 5\n";
std::cout << Ball5;
std::cout << "\nBall 6\n";
std::cout << Ball6;
return 0;
}