-
-
Save gort818/99557707150abd0679f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <cstdlib> | |
using namespace std; | |
void get_lotto_picks(int[],int); | |
bool no_duplicates(int[], int); | |
int main() | |
{ | |
const int SIZE = 7; | |
int user_ticket[SIZE]; | |
get_lotto_picks(user_ticket,SIZE); | |
} | |
void get_lotto_picks(int pick[], int SIZE) | |
{ | |
cout<<"Please enter your 7 lotto number picks between 1 and 40.\n"; | |
for(int count = 0; count < SIZE; count++) | |
{ | |
cout<<"Selection #"<<count +1<<": "; | |
cin>>pick[count]; | |
if(no_duplicates(pick, SIZE)) | |
{ | |
cout<<"You already picked this number. Please enter a different number:\n"; | |
count--; | |
} | |
if(pick[count] < 1 || pick[count] > 40) | |
{ | |
cout<<"The number must be between 1 and 40. Please try again:\n"; | |
count--; | |
} | |
} | |
} | |
bool no_duplicates(int array_dup[], int SIZE) | |
{ | |
for( int i =0; i <SIZE ;i++ ) | |
{ | |
if(array_dup[i] == array_dup[i+1]) | |
{ | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment