A game consists of asking the user to enter a random number of positive integers
ID: 3583372 • Letter: A
Question
A game consists of asking the user to enter a random number of positive integers. The winning prize depends on the lowest and the largest among the integers: The winning prize is 1000 dollars if both max and min are odd. The winning prize is 500 dollars if both max and min are even. The winning prize is 100 dollars in all other cases. Please write a C++ program to design the game and test the following entry: 3 7 45 78 67 Your Program should display: The minimum value The maximum value The winning prize Which examples of combinations of 5 random numbers can make you win 2, 700 dollars in case you are allowed to play as much as you want?Explanation / Answer
Here I am assuming random number is generatef between 0 and 1000 for understanding.You can generated random number between any limit.Just replace 1000 with any number and u will get randowm number between that ranges
Please refer below code
#include<iostream>
#include<ctime>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int win_amount;
srand(time(NULL));
int random_integer = rand() % 1000;
std::vector<int> vect;
cout<<"Random number generated : "<<random_integer;
cout<<" Array is "<<endl;
//generating random number between 0 and 1000 for understanding and adding in vector
for(int i = 0; i < random_integer; i++)
{
int test = rand() % 1000;
vect.push_back(test);
cout<<test<<" ";
}
//finding min element from vector
int min_ele = *std::min_element(vect.begin(), vect.end());
//finding max element from vector
int max_ele = *std::max_element(vect.begin(),vect.end());
cout<<" Minimum element : "<<min_ele<<endl;
cout<<" Maximum element : "<<max_ele<<endl;
//if both max and min are even
if(!(min_ele % 2) && !(max_ele % 2))
{
win_amount = 500;
}
//if both max and min are even
else if((min_ele % 2) && (max_ele % 2))
win_amount = 1000;
else
win_amount = 100;
cout<<"The winning prize is : "<<win_amount<<endl;
return 0;
}
2) Below combination can get 2700 dollars as winning amount
i) for two random number generation cases we want both max and min as odd
ii) For one case we want both max and min as even.
iii) for 2 number of times we want any one of max and min element to be odd or even.
so winning amount = 2*1000 + 1 * 500 + 2 * 100;
Please refer below output for your reference
Random number generated : 735
Array is
551 413 555 200 362 339 136 143 114 842 287 255 697 395 507 113 248 166 343 692 378 723 682 434 599 840 941 397 298 379 305 146 372 935 204 468 194 52
285 116 5 794 950 184 513 174 938 330 760 905 175 147 671 589 213 424 193 282 335 675 883 544 794 700 569 533 724 906 615 161 287 324 817 736 942 149
135 551 975 224 451 787 2 880 557 247 433 316 569 613 688 281 191 967 6 599 572 869 84 960 703 313 318 663 591 650 968 158 123 126 12 114 553 612
689 419 107 904 373 46 182 800 214 453 925 959 501 515 415 808 580 240 988 46 961 571 589 257 524 681 92 619 310 865 362 611 123 986 840 194 169 559
712 84 689 362 773 882 781 38 424 254 227 585 981 14 441 106 517 548 129 816 573 637 775 420 774 289 521 735 262 563 366 182 280 442 378 101 871 54
921 698 65 310 370 460 946 994 622 28 69 717 560 426 771 373 255 499 517 886 818 977 556 580 684 484 996 816 337 696 803 76 471 407 96 354 72 792
754 882 543 15 615 994 152 231 183 908 934 902 919 914 975 489 890 469 946 111 645 422 413 634 674 740 320 619 111 496 958 669 103 157 116 685 282 813
730 648 449 671 939 974 141 85 512 206 648 269 153 794 539 214 174 27 194 886 67 800 837 817 675 876 832 725 894 805 334 876 910 556 193 985 270 370
637 614 204 992 430 678 713 266 359 878 518 452 900 546 881 29 530 437 360 891 229 304 373 152 99 623 331 460 24 521 872 290 768 223 84 639 748 974
905 577 79 72 58 412 705 799 409 395 582 676 476 52 103 503 384 813 273 464 889 94 228 302 25 479 423 366 743 868 866 326 649 622 813 490 509 571
503 614 636 833 681 357 208 231 940 50 240 188 80 77 42 588 310 777 952 528 857 4 494 862 32 790 578 73 735 29 533 58 943 615 721 287 115 810
532 387 677 793 52 453 112 112 195 766 759 442 982 269 157 296 976 430 639 5 660 379 87 624 354 392 818 10 233 13 4 329 215 712 466 931 181 633
329 255 623 378 974 449 154 919 477 212 86 610 365 733 502 835 475 413 221 789 439 591 380 884 836 251 50 790 444 554 555 527 451 859 315 874 874 69
613 933 567 150 207 68 267 852 193 513 341 266 870 162 797 341 241 243 627 575 548 438 193 332 277 248 870 83 290 94 61 159 142 79 549 783 820 700
690 131 620 333 188 328 132 814 334 61 73 282 530 879 318 95 747 594 627 218 507 289 354 340 582 0 470 206 70 519 589 328 889 690 384 224 120 247
24 281 241 671 539 506 759 169 687 433 352 252 758 408 880 875 571 78 469 918 429 473 914 270 41 402 103 232 956 425 841 871 657 724 622 979 176 194
364 494 776 749 242 105 694 327 343 210 30 699 969 665 258 816 161 916 657 602 790 655 217 489 119 551 632 766 101 145 695 938 991 334 497 802 96 843
170 337 846 862 379 60 12 579 605 715 491 840 708 766 85 901 455 47 554 913 341 959 214 681 913 411 122 209 249 48 505 200 27 804 407 207 985 408
509 114 528 499 184 931 795 432 107 803 61 739 114 779 663 15 713 522 590 292 299 375 992 567 119 105 513 179 176 821 777 687 589 384 720 271 352 813
702 527 962 849 908 53 831 246 38 111 102 653 125
Minimum element : 0
Maximum element : 996
The winning prize is : 500
Process returned 0 (0x0) execution time : 0.370 s
Press any key to continue.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.