Develop a program called National_lottery that determines the winning lottery numbers. The program must use the rand function to produce six(6) random numbers between 0 & 49 & number must not repeat. The numbers are generated by a user by clicking a button called Generate six(6) numbers.
-Then use an appropriate pointer operator to print the addresses of the numbers in memory & must be expressed in hexadecimals.
-use the derefencing operatorto point to values contained within the addresses. Use the function sort with begin() & end() function.
-Then assign the values into an array called winning_numbers. Use the for statement or the initialiser list to initialise the numbers into the array. Search the winning_numbers for any two(2) array elements(subscripts) that give the sum of >= 80 when added together, if the numbers >= 80 are more than one(1) set, consider the biggest set to be the one chosen for draw
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <time.h>
using namespace std;
int main(){
srand(time(NULL));
int winning_numbers[6];
int i = 1, temp;
bool flag = false;
winning_numbers[0] = rand() % 50;
while(i < 6){
temp = rand() % 50;
for(int j = 0; j < i; j++){
if(temp == winning_numbers[j]){
flag = true;
}
}
if(flag){
flag = false;
continue;
}
else{
winning_numbers[i] = temp;
i++;
}
}
cout<<"Addresses of winning numberes\n";
for(i = 0; i < 6; i++){
cout<<&winning_numbers[i]<<" ";
}
cout<<endl;
sort(winning_numbers, winning_numbers + 6);
for(i = 0; i < 6; i++){
cout<<winning_numbers[i]<<" ";
}
if(winning_numbers[4] + winning_numbers[5] >= 80){
cout<<"\nNumbers chosen for the draw"<<winning_numbers[4]<<" and "<<winning_numbers[5];
}
return 0;
}
Comments
Leave a comment