Beginner making a lotto program with no cins, can't figure out how to compare all numbers












-1















Here are my assignment instructions:




You are to write a program which will do the Lotto.



The lotto consists of 5 numbers from 1-70 and a power ball from
numbers 1-30.



The first 5 numbers should not repeat (same for the winning numbers).
The power ball can repeat with any of the first 5 numbers.



You are going to purchase 10,000 lotto tickets. Each ticket has 6
numbers (5 num and 1 pow).



Give each ticket random numbers, and compare to the winning numbers
(winning numbers generated only once).



Match the 5 numbers and the power ball number and you win the jackpot!



Match 5 numbers only and you win $1,000,000.



Match 4 numbers only and you win $50,000.



Match 3 numbers only and you win $7.



Match under 3 numbers, but you got the power ball and you win $4.



anything else wins nothing.




Here is my code:



#include<iostream>
#include<time.h>
using namespace std;
int main()
{
srand(time(0));
int nums[6];
int powerball;
nums[5] = powerball;
int win5p;
int win5;
int win4;
int win3;
int winu3p;

for (int x = 0; x <= 10; x++)
{
cout << "The generated numbers are:" << endl;
for (int x = 0; x <= 5; x++)
{
nums[x] = rand() % 71 + 1;
cout << nums[x] << endl;
}
for (int x = 0; x < 1; x++)
{
cout << "The generated powerball is:" << endl;
powerball = rand() % 31 + 1;
cout << powerball << endl;
}
}

int compnums[6];
int comppowerball;
compnums[5] = comppowerball;

for (int x = 0; x <= 10; x++)
{
cout << "The winning numbers are:" << endl;
for (int x = 0; x <= 5; x++)
{
compnums[x] = rand() % 71 + 1;
cout << compnums[x] << endl;
}

cout << "The winning powerball is:" << endl;
for (int x = 0; x < 1; x++)
{
comppowerball = rand() % 31 + 1;
cout << comppowerball << endl;
}

for (int x = 0; x <= 5; x++)
{
if ((nums[0] == compnums[x]) && (nums[1] == compnums[x]) && (nums[2] == compnums[x]) && (nums[3] == compnums[x]) && (nums[4] == compnums[x]) && (nums[5] == compnums[x]) && (powerball == comppowerball))
{
win5p = true;
}
if ((nums[0] == compnums[x]) && (nums[1] == compnums[x]) && (nums[2] == compnums[x]) && (nums[3] == compnums[x]) && (nums[4] == compnums[x]) && (nums[5] == compnums[x]))
{
win5 = true;
}
// I get lost right here. I don't even know if I'm doing any of this correctly.
}
}


Yeah. If anyone could please help me, I'd be the happiest girl ever.
I have 10 instead of 10,000 tickets so it is easier for me to look through when debugging, but it will have to be 10,000 when I am finished. Matching lotto numbers can be in any place, so if numbers[1] matches with compnumbers[4], it still would be counted as matching. Please ask any questions you need to ask, I know this is a big mess.










share|improve this question

























  • I don't want to read through your code, match it to the list of requirements and then tell you what you need to do. I want you to state what the problem is that you're currently having, show the input and output from your program, state what the expected output is, and ask an actual question.

    – paddy
    Nov 16 '18 at 1:49






  • 1





    When you write code, start with something small an simple that works perfectly, then add complexity a little at a time, testing at every step, and never add to code that doesn't work. (Funny how they never seem to teach this in CompSci courses.) Call a legal set of 5+1 numbers a "ticket"/ Try writing a function that will generate a random legal ticket. Independently try writing a function that compares two tickets. Don't write anything else until both of those work perfectly.

    – Beta
    Nov 16 '18 at 1:57
















-1















Here are my assignment instructions:




You are to write a program which will do the Lotto.



The lotto consists of 5 numbers from 1-70 and a power ball from
numbers 1-30.



The first 5 numbers should not repeat (same for the winning numbers).
The power ball can repeat with any of the first 5 numbers.



You are going to purchase 10,000 lotto tickets. Each ticket has 6
numbers (5 num and 1 pow).



Give each ticket random numbers, and compare to the winning numbers
(winning numbers generated only once).



Match the 5 numbers and the power ball number and you win the jackpot!



Match 5 numbers only and you win $1,000,000.



Match 4 numbers only and you win $50,000.



Match 3 numbers only and you win $7.



Match under 3 numbers, but you got the power ball and you win $4.



anything else wins nothing.




Here is my code:



#include<iostream>
#include<time.h>
using namespace std;
int main()
{
srand(time(0));
int nums[6];
int powerball;
nums[5] = powerball;
int win5p;
int win5;
int win4;
int win3;
int winu3p;

for (int x = 0; x <= 10; x++)
{
cout << "The generated numbers are:" << endl;
for (int x = 0; x <= 5; x++)
{
nums[x] = rand() % 71 + 1;
cout << nums[x] << endl;
}
for (int x = 0; x < 1; x++)
{
cout << "The generated powerball is:" << endl;
powerball = rand() % 31 + 1;
cout << powerball << endl;
}
}

int compnums[6];
int comppowerball;
compnums[5] = comppowerball;

for (int x = 0; x <= 10; x++)
{
cout << "The winning numbers are:" << endl;
for (int x = 0; x <= 5; x++)
{
compnums[x] = rand() % 71 + 1;
cout << compnums[x] << endl;
}

cout << "The winning powerball is:" << endl;
for (int x = 0; x < 1; x++)
{
comppowerball = rand() % 31 + 1;
cout << comppowerball << endl;
}

for (int x = 0; x <= 5; x++)
{
if ((nums[0] == compnums[x]) && (nums[1] == compnums[x]) && (nums[2] == compnums[x]) && (nums[3] == compnums[x]) && (nums[4] == compnums[x]) && (nums[5] == compnums[x]) && (powerball == comppowerball))
{
win5p = true;
}
if ((nums[0] == compnums[x]) && (nums[1] == compnums[x]) && (nums[2] == compnums[x]) && (nums[3] == compnums[x]) && (nums[4] == compnums[x]) && (nums[5] == compnums[x]))
{
win5 = true;
}
// I get lost right here. I don't even know if I'm doing any of this correctly.
}
}


Yeah. If anyone could please help me, I'd be the happiest girl ever.
I have 10 instead of 10,000 tickets so it is easier for me to look through when debugging, but it will have to be 10,000 when I am finished. Matching lotto numbers can be in any place, so if numbers[1] matches with compnumbers[4], it still would be counted as matching. Please ask any questions you need to ask, I know this is a big mess.










share|improve this question

























  • I don't want to read through your code, match it to the list of requirements and then tell you what you need to do. I want you to state what the problem is that you're currently having, show the input and output from your program, state what the expected output is, and ask an actual question.

    – paddy
    Nov 16 '18 at 1:49






  • 1





    When you write code, start with something small an simple that works perfectly, then add complexity a little at a time, testing at every step, and never add to code that doesn't work. (Funny how they never seem to teach this in CompSci courses.) Call a legal set of 5+1 numbers a "ticket"/ Try writing a function that will generate a random legal ticket. Independently try writing a function that compares two tickets. Don't write anything else until both of those work perfectly.

    – Beta
    Nov 16 '18 at 1:57














-1












-1








-1








Here are my assignment instructions:




You are to write a program which will do the Lotto.



The lotto consists of 5 numbers from 1-70 and a power ball from
numbers 1-30.



The first 5 numbers should not repeat (same for the winning numbers).
The power ball can repeat with any of the first 5 numbers.



You are going to purchase 10,000 lotto tickets. Each ticket has 6
numbers (5 num and 1 pow).



Give each ticket random numbers, and compare to the winning numbers
(winning numbers generated only once).



Match the 5 numbers and the power ball number and you win the jackpot!



Match 5 numbers only and you win $1,000,000.



Match 4 numbers only and you win $50,000.



Match 3 numbers only and you win $7.



Match under 3 numbers, but you got the power ball and you win $4.



anything else wins nothing.




Here is my code:



#include<iostream>
#include<time.h>
using namespace std;
int main()
{
srand(time(0));
int nums[6];
int powerball;
nums[5] = powerball;
int win5p;
int win5;
int win4;
int win3;
int winu3p;

for (int x = 0; x <= 10; x++)
{
cout << "The generated numbers are:" << endl;
for (int x = 0; x <= 5; x++)
{
nums[x] = rand() % 71 + 1;
cout << nums[x] << endl;
}
for (int x = 0; x < 1; x++)
{
cout << "The generated powerball is:" << endl;
powerball = rand() % 31 + 1;
cout << powerball << endl;
}
}

int compnums[6];
int comppowerball;
compnums[5] = comppowerball;

for (int x = 0; x <= 10; x++)
{
cout << "The winning numbers are:" << endl;
for (int x = 0; x <= 5; x++)
{
compnums[x] = rand() % 71 + 1;
cout << compnums[x] << endl;
}

cout << "The winning powerball is:" << endl;
for (int x = 0; x < 1; x++)
{
comppowerball = rand() % 31 + 1;
cout << comppowerball << endl;
}

for (int x = 0; x <= 5; x++)
{
if ((nums[0] == compnums[x]) && (nums[1] == compnums[x]) && (nums[2] == compnums[x]) && (nums[3] == compnums[x]) && (nums[4] == compnums[x]) && (nums[5] == compnums[x]) && (powerball == comppowerball))
{
win5p = true;
}
if ((nums[0] == compnums[x]) && (nums[1] == compnums[x]) && (nums[2] == compnums[x]) && (nums[3] == compnums[x]) && (nums[4] == compnums[x]) && (nums[5] == compnums[x]))
{
win5 = true;
}
// I get lost right here. I don't even know if I'm doing any of this correctly.
}
}


Yeah. If anyone could please help me, I'd be the happiest girl ever.
I have 10 instead of 10,000 tickets so it is easier for me to look through when debugging, but it will have to be 10,000 when I am finished. Matching lotto numbers can be in any place, so if numbers[1] matches with compnumbers[4], it still would be counted as matching. Please ask any questions you need to ask, I know this is a big mess.










share|improve this question
















Here are my assignment instructions:




You are to write a program which will do the Lotto.



The lotto consists of 5 numbers from 1-70 and a power ball from
numbers 1-30.



The first 5 numbers should not repeat (same for the winning numbers).
The power ball can repeat with any of the first 5 numbers.



You are going to purchase 10,000 lotto tickets. Each ticket has 6
numbers (5 num and 1 pow).



Give each ticket random numbers, and compare to the winning numbers
(winning numbers generated only once).



Match the 5 numbers and the power ball number and you win the jackpot!



Match 5 numbers only and you win $1,000,000.



Match 4 numbers only and you win $50,000.



Match 3 numbers only and you win $7.



Match under 3 numbers, but you got the power ball and you win $4.



anything else wins nothing.




Here is my code:



#include<iostream>
#include<time.h>
using namespace std;
int main()
{
srand(time(0));
int nums[6];
int powerball;
nums[5] = powerball;
int win5p;
int win5;
int win4;
int win3;
int winu3p;

for (int x = 0; x <= 10; x++)
{
cout << "The generated numbers are:" << endl;
for (int x = 0; x <= 5; x++)
{
nums[x] = rand() % 71 + 1;
cout << nums[x] << endl;
}
for (int x = 0; x < 1; x++)
{
cout << "The generated powerball is:" << endl;
powerball = rand() % 31 + 1;
cout << powerball << endl;
}
}

int compnums[6];
int comppowerball;
compnums[5] = comppowerball;

for (int x = 0; x <= 10; x++)
{
cout << "The winning numbers are:" << endl;
for (int x = 0; x <= 5; x++)
{
compnums[x] = rand() % 71 + 1;
cout << compnums[x] << endl;
}

cout << "The winning powerball is:" << endl;
for (int x = 0; x < 1; x++)
{
comppowerball = rand() % 31 + 1;
cout << comppowerball << endl;
}

for (int x = 0; x <= 5; x++)
{
if ((nums[0] == compnums[x]) && (nums[1] == compnums[x]) && (nums[2] == compnums[x]) && (nums[3] == compnums[x]) && (nums[4] == compnums[x]) && (nums[5] == compnums[x]) && (powerball == comppowerball))
{
win5p = true;
}
if ((nums[0] == compnums[x]) && (nums[1] == compnums[x]) && (nums[2] == compnums[x]) && (nums[3] == compnums[x]) && (nums[4] == compnums[x]) && (nums[5] == compnums[x]))
{
win5 = true;
}
// I get lost right here. I don't even know if I'm doing any of this correctly.
}
}


Yeah. If anyone could please help me, I'd be the happiest girl ever.
I have 10 instead of 10,000 tickets so it is easier for me to look through when debugging, but it will have to be 10,000 when I am finished. Matching lotto numbers can be in any place, so if numbers[1] matches with compnumbers[4], it still would be counted as matching. Please ask any questions you need to ask, I know this is a big mess.







c++ arrays if-statement variable-assignment






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 2:58









Simply Ged

2,72631625




2,72631625










asked Nov 16 '18 at 1:45









vanilla vigilantevanilla vigilante

1




1













  • I don't want to read through your code, match it to the list of requirements and then tell you what you need to do. I want you to state what the problem is that you're currently having, show the input and output from your program, state what the expected output is, and ask an actual question.

    – paddy
    Nov 16 '18 at 1:49






  • 1





    When you write code, start with something small an simple that works perfectly, then add complexity a little at a time, testing at every step, and never add to code that doesn't work. (Funny how they never seem to teach this in CompSci courses.) Call a legal set of 5+1 numbers a "ticket"/ Try writing a function that will generate a random legal ticket. Independently try writing a function that compares two tickets. Don't write anything else until both of those work perfectly.

    – Beta
    Nov 16 '18 at 1:57



















  • I don't want to read through your code, match it to the list of requirements and then tell you what you need to do. I want you to state what the problem is that you're currently having, show the input and output from your program, state what the expected output is, and ask an actual question.

    – paddy
    Nov 16 '18 at 1:49






  • 1





    When you write code, start with something small an simple that works perfectly, then add complexity a little at a time, testing at every step, and never add to code that doesn't work. (Funny how they never seem to teach this in CompSci courses.) Call a legal set of 5+1 numbers a "ticket"/ Try writing a function that will generate a random legal ticket. Independently try writing a function that compares two tickets. Don't write anything else until both of those work perfectly.

    – Beta
    Nov 16 '18 at 1:57

















I don't want to read through your code, match it to the list of requirements and then tell you what you need to do. I want you to state what the problem is that you're currently having, show the input and output from your program, state what the expected output is, and ask an actual question.

– paddy
Nov 16 '18 at 1:49





I don't want to read through your code, match it to the list of requirements and then tell you what you need to do. I want you to state what the problem is that you're currently having, show the input and output from your program, state what the expected output is, and ask an actual question.

– paddy
Nov 16 '18 at 1:49




1




1





When you write code, start with something small an simple that works perfectly, then add complexity a little at a time, testing at every step, and never add to code that doesn't work. (Funny how they never seem to teach this in CompSci courses.) Call a legal set of 5+1 numbers a "ticket"/ Try writing a function that will generate a random legal ticket. Independently try writing a function that compares two tickets. Don't write anything else until both of those work perfectly.

– Beta
Nov 16 '18 at 1:57





When you write code, start with something small an simple that works perfectly, then add complexity a little at a time, testing at every step, and never add to code that doesn't work. (Funny how they never seem to teach this in CompSci courses.) Call a legal set of 5+1 numbers a "ticket"/ Try writing a function that will generate a random legal ticket. Independently try writing a function that compares two tickets. Don't write anything else until both of those work perfectly.

– Beta
Nov 16 '18 at 1:57












1 Answer
1






active

oldest

votes


















0














#include <iostream>
#include<cstdlib>
#include <time.h>
using namespace std;
int main() {
srand(time(0));
int count=0;
bool powerball=false; // to check if powerball matches
int luckyarr[5]; // the winning numbers
int luckypb=rand()%30+1; //lucky pb
cout <<"Showing result for only won Lottosn";
cout <<"Lucky numbers: ";
for(int i=0;i<5;i++){
luckyarr[i]=rand()%70+1;
if(i>0){ // line 15-22 checking if the number already exists or not
for(int m=0; m<i;m++){
if(luckyarr[i]==luckyarr[m]){ // it compares the new number with all previous values
i-=2; // reduces i by 2 so that i++ in line 13 will make the difference =1 and new num will be generated in place of the previous num which was same
break;
}
}
}
cout <<luckyarr[i] << " ";
}
cout << "Powerball: "<<luckypb<<endl;
cout <<"Showing result for only won Lottosn";
int arr[5];
int pb;
for(int j=1; j<=1000;j++){ //running loop 10000 times as we are buying 10,000 tickets
for(int i=0; i<5;i++){
arr[i]=rand()%70+1; // generating numbers for jth ticket
if(i>0){
for(int m=0; m<i;m++){ //chechking similar numbers
if(luckyarr[i]==luckyarr[m]){
i-=2;
break;
}
}
}
for(int k=0;k<5;k++){
if(arr[i]==luckyarr[k]) count++; // counting the number of matching numbers of jth ticket
}
}
pb=rand()%30+1;
if(pb==luckypb){
powerball=true; // checking if pb matches
}

if(count>0 || powerball){
cout << "For Lotto no."<< j<< ": ";
switch (count) {
case 5:
if(powerball) cout <<"You have won the Jackpot.n";
else cout << "You have won $1,000,000n";
break;
case 4:
cout <<"You have won $50,000n";
break;
case 3:
cout <<"You have won $7n";
case 2:
if(powerball) cout <<"You matched 2 number and powerball and have won $3n";
break;
case 1:
if(powerball) cout <<"You matched only 1 number powerball and have won $3n";
break;
case 0:
if(powerball) cout <<"You matched only powerball and You have won $3n";
break;
}
count=0; // resetting count and pb for next ticket
powerball=false;
}


}


return 0;
}





share|improve this answer
























  • I didn't understand your code. It took a while but it was fun :P Hope it works for you. If you don't understand anything or need any change, inbox me

    – Hamza Mahmood
    Nov 16 '18 at 3:52











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330301%2fbeginner-making-a-lotto-program-with-no-cins-cant-figure-out-how-to-compare-al%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














#include <iostream>
#include<cstdlib>
#include <time.h>
using namespace std;
int main() {
srand(time(0));
int count=0;
bool powerball=false; // to check if powerball matches
int luckyarr[5]; // the winning numbers
int luckypb=rand()%30+1; //lucky pb
cout <<"Showing result for only won Lottosn";
cout <<"Lucky numbers: ";
for(int i=0;i<5;i++){
luckyarr[i]=rand()%70+1;
if(i>0){ // line 15-22 checking if the number already exists or not
for(int m=0; m<i;m++){
if(luckyarr[i]==luckyarr[m]){ // it compares the new number with all previous values
i-=2; // reduces i by 2 so that i++ in line 13 will make the difference =1 and new num will be generated in place of the previous num which was same
break;
}
}
}
cout <<luckyarr[i] << " ";
}
cout << "Powerball: "<<luckypb<<endl;
cout <<"Showing result for only won Lottosn";
int arr[5];
int pb;
for(int j=1; j<=1000;j++){ //running loop 10000 times as we are buying 10,000 tickets
for(int i=0; i<5;i++){
arr[i]=rand()%70+1; // generating numbers for jth ticket
if(i>0){
for(int m=0; m<i;m++){ //chechking similar numbers
if(luckyarr[i]==luckyarr[m]){
i-=2;
break;
}
}
}
for(int k=0;k<5;k++){
if(arr[i]==luckyarr[k]) count++; // counting the number of matching numbers of jth ticket
}
}
pb=rand()%30+1;
if(pb==luckypb){
powerball=true; // checking if pb matches
}

if(count>0 || powerball){
cout << "For Lotto no."<< j<< ": ";
switch (count) {
case 5:
if(powerball) cout <<"You have won the Jackpot.n";
else cout << "You have won $1,000,000n";
break;
case 4:
cout <<"You have won $50,000n";
break;
case 3:
cout <<"You have won $7n";
case 2:
if(powerball) cout <<"You matched 2 number and powerball and have won $3n";
break;
case 1:
if(powerball) cout <<"You matched only 1 number powerball and have won $3n";
break;
case 0:
if(powerball) cout <<"You matched only powerball and You have won $3n";
break;
}
count=0; // resetting count and pb for next ticket
powerball=false;
}


}


return 0;
}





share|improve this answer
























  • I didn't understand your code. It took a while but it was fun :P Hope it works for you. If you don't understand anything or need any change, inbox me

    – Hamza Mahmood
    Nov 16 '18 at 3:52
















0














#include <iostream>
#include<cstdlib>
#include <time.h>
using namespace std;
int main() {
srand(time(0));
int count=0;
bool powerball=false; // to check if powerball matches
int luckyarr[5]; // the winning numbers
int luckypb=rand()%30+1; //lucky pb
cout <<"Showing result for only won Lottosn";
cout <<"Lucky numbers: ";
for(int i=0;i<5;i++){
luckyarr[i]=rand()%70+1;
if(i>0){ // line 15-22 checking if the number already exists or not
for(int m=0; m<i;m++){
if(luckyarr[i]==luckyarr[m]){ // it compares the new number with all previous values
i-=2; // reduces i by 2 so that i++ in line 13 will make the difference =1 and new num will be generated in place of the previous num which was same
break;
}
}
}
cout <<luckyarr[i] << " ";
}
cout << "Powerball: "<<luckypb<<endl;
cout <<"Showing result for only won Lottosn";
int arr[5];
int pb;
for(int j=1; j<=1000;j++){ //running loop 10000 times as we are buying 10,000 tickets
for(int i=0; i<5;i++){
arr[i]=rand()%70+1; // generating numbers for jth ticket
if(i>0){
for(int m=0; m<i;m++){ //chechking similar numbers
if(luckyarr[i]==luckyarr[m]){
i-=2;
break;
}
}
}
for(int k=0;k<5;k++){
if(arr[i]==luckyarr[k]) count++; // counting the number of matching numbers of jth ticket
}
}
pb=rand()%30+1;
if(pb==luckypb){
powerball=true; // checking if pb matches
}

if(count>0 || powerball){
cout << "For Lotto no."<< j<< ": ";
switch (count) {
case 5:
if(powerball) cout <<"You have won the Jackpot.n";
else cout << "You have won $1,000,000n";
break;
case 4:
cout <<"You have won $50,000n";
break;
case 3:
cout <<"You have won $7n";
case 2:
if(powerball) cout <<"You matched 2 number and powerball and have won $3n";
break;
case 1:
if(powerball) cout <<"You matched only 1 number powerball and have won $3n";
break;
case 0:
if(powerball) cout <<"You matched only powerball and You have won $3n";
break;
}
count=0; // resetting count and pb for next ticket
powerball=false;
}


}


return 0;
}





share|improve this answer
























  • I didn't understand your code. It took a while but it was fun :P Hope it works for you. If you don't understand anything or need any change, inbox me

    – Hamza Mahmood
    Nov 16 '18 at 3:52














0












0








0







#include <iostream>
#include<cstdlib>
#include <time.h>
using namespace std;
int main() {
srand(time(0));
int count=0;
bool powerball=false; // to check if powerball matches
int luckyarr[5]; // the winning numbers
int luckypb=rand()%30+1; //lucky pb
cout <<"Showing result for only won Lottosn";
cout <<"Lucky numbers: ";
for(int i=0;i<5;i++){
luckyarr[i]=rand()%70+1;
if(i>0){ // line 15-22 checking if the number already exists or not
for(int m=0; m<i;m++){
if(luckyarr[i]==luckyarr[m]){ // it compares the new number with all previous values
i-=2; // reduces i by 2 so that i++ in line 13 will make the difference =1 and new num will be generated in place of the previous num which was same
break;
}
}
}
cout <<luckyarr[i] << " ";
}
cout << "Powerball: "<<luckypb<<endl;
cout <<"Showing result for only won Lottosn";
int arr[5];
int pb;
for(int j=1; j<=1000;j++){ //running loop 10000 times as we are buying 10,000 tickets
for(int i=0; i<5;i++){
arr[i]=rand()%70+1; // generating numbers for jth ticket
if(i>0){
for(int m=0; m<i;m++){ //chechking similar numbers
if(luckyarr[i]==luckyarr[m]){
i-=2;
break;
}
}
}
for(int k=0;k<5;k++){
if(arr[i]==luckyarr[k]) count++; // counting the number of matching numbers of jth ticket
}
}
pb=rand()%30+1;
if(pb==luckypb){
powerball=true; // checking if pb matches
}

if(count>0 || powerball){
cout << "For Lotto no."<< j<< ": ";
switch (count) {
case 5:
if(powerball) cout <<"You have won the Jackpot.n";
else cout << "You have won $1,000,000n";
break;
case 4:
cout <<"You have won $50,000n";
break;
case 3:
cout <<"You have won $7n";
case 2:
if(powerball) cout <<"You matched 2 number and powerball and have won $3n";
break;
case 1:
if(powerball) cout <<"You matched only 1 number powerball and have won $3n";
break;
case 0:
if(powerball) cout <<"You matched only powerball and You have won $3n";
break;
}
count=0; // resetting count and pb for next ticket
powerball=false;
}


}


return 0;
}





share|improve this answer













#include <iostream>
#include<cstdlib>
#include <time.h>
using namespace std;
int main() {
srand(time(0));
int count=0;
bool powerball=false; // to check if powerball matches
int luckyarr[5]; // the winning numbers
int luckypb=rand()%30+1; //lucky pb
cout <<"Showing result for only won Lottosn";
cout <<"Lucky numbers: ";
for(int i=0;i<5;i++){
luckyarr[i]=rand()%70+1;
if(i>0){ // line 15-22 checking if the number already exists or not
for(int m=0; m<i;m++){
if(luckyarr[i]==luckyarr[m]){ // it compares the new number with all previous values
i-=2; // reduces i by 2 so that i++ in line 13 will make the difference =1 and new num will be generated in place of the previous num which was same
break;
}
}
}
cout <<luckyarr[i] << " ";
}
cout << "Powerball: "<<luckypb<<endl;
cout <<"Showing result for only won Lottosn";
int arr[5];
int pb;
for(int j=1; j<=1000;j++){ //running loop 10000 times as we are buying 10,000 tickets
for(int i=0; i<5;i++){
arr[i]=rand()%70+1; // generating numbers for jth ticket
if(i>0){
for(int m=0; m<i;m++){ //chechking similar numbers
if(luckyarr[i]==luckyarr[m]){
i-=2;
break;
}
}
}
for(int k=0;k<5;k++){
if(arr[i]==luckyarr[k]) count++; // counting the number of matching numbers of jth ticket
}
}
pb=rand()%30+1;
if(pb==luckypb){
powerball=true; // checking if pb matches
}

if(count>0 || powerball){
cout << "For Lotto no."<< j<< ": ";
switch (count) {
case 5:
if(powerball) cout <<"You have won the Jackpot.n";
else cout << "You have won $1,000,000n";
break;
case 4:
cout <<"You have won $50,000n";
break;
case 3:
cout <<"You have won $7n";
case 2:
if(powerball) cout <<"You matched 2 number and powerball and have won $3n";
break;
case 1:
if(powerball) cout <<"You matched only 1 number powerball and have won $3n";
break;
case 0:
if(powerball) cout <<"You matched only powerball and You have won $3n";
break;
}
count=0; // resetting count and pb for next ticket
powerball=false;
}


}


return 0;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 16 '18 at 3:49









Hamza MahmoodHamza Mahmood

12




12













  • I didn't understand your code. It took a while but it was fun :P Hope it works for you. If you don't understand anything or need any change, inbox me

    – Hamza Mahmood
    Nov 16 '18 at 3:52



















  • I didn't understand your code. It took a while but it was fun :P Hope it works for you. If you don't understand anything or need any change, inbox me

    – Hamza Mahmood
    Nov 16 '18 at 3:52

















I didn't understand your code. It took a while but it was fun :P Hope it works for you. If you don't understand anything or need any change, inbox me

– Hamza Mahmood
Nov 16 '18 at 3:52





I didn't understand your code. It took a while but it was fun :P Hope it works for you. If you don't understand anything or need any change, inbox me

– Hamza Mahmood
Nov 16 '18 at 3:52




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330301%2fbeginner-making-a-lotto-program-with-no-cins-cant-figure-out-how-to-compare-al%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python