Answer to Question #248669 in C++ for sandyjay

Question #248669

Write a program called National_lottery. it should use rand function to produce 6 random numbers to 0 & 49, number must not repeat. use an appropriate pointer to print address of numbers in memory and its must be in hexadecimal. use derefencing operator to point in address. use function sort with begin() & end() function to organise values in ascending order, use a for statement to intialise numbers into arrays. Search any 2 array element that give sum of >=80 when added together, if numbers >=80 are more than one set, consider the biggest set chosen for draw. if the value of sum of the two are >=80, print "You W" & if they are < 80, print "You L". Amount won by custom made function amountDeterminat of type & double argument in prototype. argument will be winning number received from sum of 2 numbers. amountDeterminant must use switch conditions. if winning numbers is (80-83 won amount 1700000, 84-86 R2500000, 87-98 R16000000). add this #include<vector>.


1
Expert's answer
2021-10-08T23:51:29-0400


#include<cstdlib> 
#include <iostream>
#include <algorithm>
#include<ctime>   
#include <iomanip>
using namespace std;
double amountDeterminat(int win);
int main()
{
	srand(time(NULL));
	int random_numbers[6];












	
	for(int i=0;i<6;i++){
		random_numbers[i] = rand() % 50;
	}








	sort(begin(random_numbers),end(random_numbers));
	cout<<"Address of elements memory\n";
	for(int i=0;i<6;i++){
		cout<<&random_numbers[i]<<" ";
	}
	cout<<"\nRandom Numbers are: \n";
	for(int i=0;i<6;i++){
		cout<<random_numbers[i]<<" ";
	}
	
	int win=0;
	for(int i=0;i<5;i++){
		int total=random_numbers[i]+random_numbers[i+1];
		if(total>=80){
			win=total;
		}
	}
	
	cout<<"\n\n";
	if(win!=0){
		cout<<"You won.\n";
		cout<<fixed<<"Won amount: "<<setprecision(2)<<amountDeterminat(win)<<"\n";	
	}else{
		cout<<"You loose.\n\n";
	}












	cout<<"\n";
	cin>>random_numbers[0];
	return 0;
}


double amountDeterminat(int win){
	switch(win){
	case 80:
	return 1700000.0; 
	break;
	case 83:
		return 1700000.0; 
		break;




	case 84: 
	       return 2500000.0;
	       break;
	case 86:
		return 2500000.0; 
		break;
	case 87:
		return 16000000.0; 
		break;
	case 89:
		return 16000000.0; 
		break;
	}
	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