Answer to Question #247942 in C++ for sandyjay

Question #247942

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 + together, if numbers >=80 are more than 1 set, consider the biggest set chosen for draw. if the value of sum of the 2 are >=80, print "You won" & if they are < 80, print "You loose". Amount won by custom made function "amountDeterminat" of type & double argument in prototype. argument will be winning number received from sum of 2. amountDeterminant must use switch conditions. if winning numbers is (80 & 83 won amount 1700000, 84 & 86 amount 2500000, 87 & 89 amount 16000000)


1
Expert's answer
2021-10-07T10:06:47-0400
#include <iostream>
#include <algorithm>
#include <iomanip>
#include<ctime>   //For time()
#include<cstdlib> //For rand() and srand()


using namespace std;






double amountDeterminat(int winningNumber);


int main()
{
	srand(time(NULL));
	int numbers[6];






	// Fill array with numbers
	for(int i=0;i<6;i++){
		numbers[i] = rand() % 50;
	}




	sort(begin(numbers),end(numbers));
	cout<<"Address of numbers in memory\n";
	for(int i=0;i<6;i++){
		cout<<&numbers[i]<<" ";
	}
	cout<<"\nNumbers\n";
	for(int i=0;i<6;i++){
		cout<<numbers[i]<<" ";
	}
	// Search any 2 array element that give sum of >=80 when + together, 
	//if numbers >=80 are more than 1 set, consider the biggest set chosen for draw. 
	//if the value of sum of the 2 are >=80, print "You won" & 
	//if they are < 80, print "You loose". 
	int winningNumber=0;
	for(int i=0;i<5;i++){
		int sum=numbers[i]+numbers[i+1];
		if(sum>=80){
			winningNumber=sum;
		}
	}
	
	cout<<"\n\n";
	if(winningNumber!=0){
		cout<<"You won.\n";
		cout<<fixed<<"Won amount: "<<setprecision(2)<<amountDeterminat(winningNumber)<<"\n";	
	}else{
		cout<<"You loose.\n\n";
	}






	cout<<"\n";
	cin>>numbers[0];
	return 0;
}
//Amount won by custom made function "amountDeterminat" of type & double argument in prototype. 
//argument will be winning number received from sum of 2. amountDeterminant must use switch conditions. 
//if winning numbers is (80 & 83 won amount 1700000, 84 & 86 amount 2500000, 87 & 89 amount 16000000)
double amountDeterminat(int winningNumber){
	switch(winningNumber){
	case 80:
	case 83:
		return 1700000.0; 
		break;


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