To start with, l'm an early beginner programmer and would like some help with this please.
Lottery programme random number generator:
I have written the following code, which from what l have tested generates:
- 5 random numbers between: 1 and 39 //num1gen to num5gen - e.g.group A
- 1 random number between: 1 and 14 //Thunderball - e.g.group B
The process repeats it's self until all of the numbers of group A are all different from each other.
I only want to cout<< the group A numbers in ascending order and l am not sure what coding is required to add this feature.
The entire remainder of my code successfully checks what was inputted (number chosen by user) against what was generated. The code for this is fairly long and works perfectly each time, hence does not need to be amended.
If the code needed to be altered l would still require the following structure:
i.e
- num1gen = 12
- num2gen = 24
- num3gen = 3
- num4gen = 5
- num5gen = 32
- Thunderball = 12
where these same integer names would hold the random numbers as shown above.
Thanks!
Below is my code:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
srand(time(NULL));
int num1gen=(rand()%49+1); // this is the value of ball no.1
int num2gen=(rand()%49+1); // this is the value of ball no.2
int num3gen=(rand()%49+1); // this is the value of ball no.3
int num4gen=(rand()%49+1); // this is the value of ball no.4
int num5gen=(rand()%49+1); // this is the value of ball no.5
int num6gen=(rand()%14+1); // this is the value of the Thunderball.
while (num1gen==num2gen || num1gen==num2gen || num1gen==num3gen ||
num1gen==num4gen|| num1gen==num5gen)
// I feel that this while statement does not account for the total amount
//of combinations possible.
{
srand(time(NULL));
int num1gen=(rand()%49+1);
int num2gen=(rand()%49+1);
int num3gen=(rand()%49+1);
int num4gen=(rand()%49+1);
int num5gen=(rand()%49+1);
int num6gen=(rand()%14+1);
}
}
Aucun commentaire:
Enregistrer un commentaire