Answer to Question #246960 in C++ for sandyjay

Question #246960

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


1
Expert's answer
2021-10-05T18:16:02-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS