i am suppose to use functions and 2 arrays for this program heres my code #inclu
ID: 3643085 • Letter: I
Question
i am suppose to use functions and 2 arrays for this programheres my code
#include <iostream>
#include <string>
#include <cctype>
#include <ctime>
using namespace std;
int getLottoPicks(int const );
int GenWinNums(int const );
bool NoDuplicate(int);
int main()
{
const int num = 7;
int UserTicket[num]; //array for users number 7 number
int WinningNums[num]; //array for random numbers to be generated for the winning#'s
int co = 0;
char Selection;
string name;
do
{
cout << "LITTLETON CITY LOTTO MODEL: ";
cout << "--------------------------- ";
cout << "1) Play Lotto ";
cout << "q) Quit Program ";
cout << "Please make a selection: ";
cin >> Selection;
if(Selection == '1')
{
cout << "Please enter your name";
getline(cin, name);
num = getLottoPicks(UserTicket[num]); // function for the users numbers
num = GenWinNums(WinningNums[num]); // function for the random winning numbers from 1 to 40
//I am not sure how to display each statement depending
// on how many users numbers matched the winning numbers.
//In the
Explanation / Answer
So basically you need the code to find the number of common elements in two arrays - WinningNums and UserTicket.
Here is the code
int i,j;
int count = 0; // number of matches
for(i=0;i<num;i++){
for(j=0;j<num;j++){
if(WinningNums[i] == UserTicket[j])
count ++;
}
}
//Display proper messages by comparing with count -- This is trivial
//Here are some errors in the codes
int void getLottoPicks(int num)
{
const int num = 7;
int UserTicket[num]; // Make this a global array, so no need to return anything
for(int co = 0; co < num; co++)
{
cout << "Please enter your 7 lotto number picks";
cin >> UserTicket[co];
cin.ignore();
}
return UserTicket[num];
}
int void GenWinNums(int const num)
{
srand ((unsigned int)time(NULL));
int const num = 7;
int const WinningNums[num]; // Make this a global array, so no need to return anything
for(co = 0; co < num; co++)
{
WinningNums[num] = rand() % 1 + 40;
}
return WinningNums[num];
}
bool NoDuplicates(int num) // function to check if there are dupicate numbers
{
for(int co = 0;co <= num ; co++)
{
if (UserTicket[num] == num || WinningNums[num] == num ) // not sure if correct
return false;
else
return false;
}
}
bool NoDuplicates(int num){
for(int i=0;i<num;i++){
for(int j=0;j<i;j++){
if(UserTicket[i] == UserTicket[j] || WinningNums[i] == WinningNums[j])
return false;
}
}
return true;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.