Program call National lottery dat give the winning lottery numbers. The program must use the rand function to produce six(6) random numbers between 0 & 49 & number must not repeat. Search the winning_numbers for any 2 array elements dat give the sum of >= 80 when added together, if the numbers >= 80 are more than 1 set, consider the biggest set to be the 1 chosen for draw. If the value of the sum of the 2 values is >= 80, print the message “You have won” & if the sum of the 2 numbers is < 80, print the message “You did not win”. a custom made function called amountDeterminant(double & receives a double argument), argument will be the winning number from the sum of 2 numbers. amountDeterminant. Winning numbers are in between 80 and 83, the won amount is R17M 84 & 86, amount is R2.5M, 87 & 89, amount is R16M
-use switch condition, appropriate pointer print "address the number" & for statement or initialiser list to the numbers into arrays
#include <iostream>
#include <time.h>
#include <algorithm>
using namespace std;
int main(){
srand(time(NULL));
int winning_numbers[6];
int i = 1, x;
bool y = false;
winning_numbers[0] = rand() % 50;
while(i < 6){
x = rand() % 50;
for(int m = 0; m < i; m++){
if(x == winning_numbers[m]){
y = true;
}
}
if(y){
y = false;
continue;
}
else{
winning_numbers[i] = x;
i++;
}
}
cout<<"The random numbers are:\n";
for(i = 0; i <=5; i++){
cout<<winning_numbers[i]<<" ";
}
sort(winning_numbers, winning_numbers + 6);
for(i = 0; i <=5 ; i++){
winning_numbers[i];
}
if(winning_numbers[4] + winning_numbers[5] >= 80){
cout<<"\nSum of the two numbers is: "<<winning_numbers[4]+winning_numbers[5];
cout<<"\nYou have won";
}
else{
cout<<"\nSum of the two numbers is: "<<winning_numbers[4]+winning_numbers[5];
cout<<"\nYou did not win";
}
return 0;
}
Comments
Leave a comment