.) Lotto is a game in which winners are chosen by random drawing of numbers from among those who have paid money to participate. Write a program that will simulate the lotto game by asking the user five numbers(use array) and should generate a random number in the range of 0-9 for each array element. The program will compare the corresponding elements in the two arrays and if a count of the digits that matches. For instance, if the lottery array contains 8,5,0,2, and 4 and the user array contains 5,3,0,8 and 4, we can say that there are three numbers that matches. The program should display the random numbers stored in the lotto array and the matching digits. If all of the digits matched, display a message proclaiming the user as a grand prize winner. Prizes are as follows:
5 matching digits- 500,000 pesos
4 matching digits-100,000 pesos
3 matching digits- 20,000 pesos
2 matching digits- 500 pesos
1 matching digits-10 pesos or Balik taya! ~(>3>)~
0 matching digits-Try Again!~(^3>)~
I use this code:
#include "stdafx.h"
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
if (MN = 5);
cout << endl << "Prize: P500,000. Congratulations! You one lucky son of a God!" << endl;
if (MN = 4);
cout << endl << "Prize: P100,000. Congratulations! The odds is in your favor!"<<endl;
if (MN = 3);
cout << endl << "Prize: P20,000. Congratulations! You can now buy an expensive item of your choice!" << endl;
if (MN = 2);
cout << endl << "Prize: P500. Yay! Added allowance!" << endl;
if (MN = 1);
cout << endl << "Prize: P10. Balik taya!" << endl;
if (MN = 0);
cout << endl << "Zero Matching Digits. Try Again.";
system("pause>0");
return 0;
}
//i'm not done yet but i have a problem in the prize part... :/
Output of my program:
LOTTO Winning Numbers: 17409
Enter 1st number: 1
Enter 2nd number: 3
Enter 3rd number: 4
Enter 4th number: 6
Enter 5th number: 7
Matching Number: 174
Prize: Prize: P500,000. Congratulations! You one lucky son of a God!
Prize: P100,000. Congratulations! The odds is in your favor!
Prize: P20,000. Congratulations! You can now buy an expensive item of your choice!
Prize: P500. Yay! Added allowance!
Prize: P10. Balik taya!
Zero Matching Digits. Try Again.
if (MN = 5)
cout << endl << "Prize: P500,000. Congratulations! You one lucky son of a God!" << endl;
else if (MN = 4)
cout << endl << "Prize: P100,000. Congratulations! The odds is in your favor!"<<endl;
else if (MN = 3)
cout << endl << "Prize: P20,000. Congratulations! You can now buy an expensive item of your choice!" << endl;
else if (MN = 2)
cout << endl << "Prize: P500. Yay! Added allowance!" << endl;
else if (MN = 1)
cout << endl << "Prize: P10. Balik taya!" << endl;
else if (MN = 0)
cout << endl << "Zero Matching Digits. Try Again.";
system("pause>0");
return 0;
}
OUTPUT PROGRAM:
LOTTO Winning Numbers: 17409
Enter 1st number: 1
Enter 2nd number: 3
Enter 3rd number: 4
Enter 4th number: 6
Enter 5th number: 7
Matching Number: 174
Prize: Prize: P500,000. Congratulations! You one lucky son of a God!
cout << "LOTTO Winning Numbers: " << WN[0] << WN[1] << WN[2] << WN[3] << WN[4] << endl;
cout << "USER Numbers: " << endl;
for (int i = 0; i < 5; i++)
{
cout << "Enter a digit between 0 and 9: ";
cin >> UI[i];
while (UI[i]<0 || UI[i]>9)
{
cout << "Error! Entry must be between 0 and 9: ";
cin >> UI[i];
}
}
for (int i = 0; i<5; i++)
{
for (int j = 0; j<5; j++)
{
if (WN[i] == UI[j])
{
MN++;
}
}
}
if (MN = 5)
cout << endl << "Prize: P500,000. Congratulations! You one lucky son of a God!" << endl;
else if (MN = 4)
cout << endl << "Prize: P100,000. Congratulations! The odds is in your favor!" << endl;
else if (MN = 3)
cout << endl << "Prize: P20,000. Congratulations! You can now buy an expensive item of your choice!" << endl;
else if (MN = 2)
cout << endl << "Prize: P500. Yay! Added allowance!" << endl;
else if (MN = 1)
cout << endl << "Prize: P10. Balik taya!" << endl;
else if (MN = 0)
cout << endl << "Zero Matching Digits. Try Again.";
cout << "LOTTO Winning Numbers: " << WN[0] << WN[1] << WN[2] << WN[3] << WN[4] << endl;
cout << "USER Numbers: " << endl;
for (int i = 0; i < 5; i++)
{
cout << "Enter a digit between 0 and 9: ";
cin >> UI[i];
while (UI[i]<0 || UI[i]>9)
{
cout << "Error! Entry must be between 0 and 9: ";
cin >> UI[i];
}
}
cout << "Matching Numbers: ";
for (int i = 0; i<5; i++)
{
for (int j = 0; j<5; j++)
{
if (WN[i] == UI[j])
cout << WN[i];
{
MN++;
}
}
}
if (MN = 5)
cout << endl << "Prize: P500,000. Congratulations! You one lucky son of a God!" << endl;
else if (MN = 4)
cout << endl << "Prize: P100,000. Congratulations! The odds is in your favor!" << endl;
else if (MN = 3)
cout << endl << "Prize: P20,000. Congratulations! You can now buy an expensive item of your choice!" << endl;
else if (MN = 2)
cout << endl << "Prize: P500. Yay! Added allowance!" << endl;
else if (MN = 1)
cout << endl << "Prize: P10. Balik taya!" << endl;
else if (MN = 0)
cout << endl << "Zero Matching Digits. Try Again.";
line 5 is not governed by the if condition. It is executed unconditionally, so MN will always be 25 after your nested loops. It would have been easier to spot if you'd bothered researching how to use code tags on this site. ;)