using namespace std; void getUserNumbers(vector <int> &U); void getLotteryNumber
ID: 3641858 • Letter: U
Question
using namespace std;
void getUserNumbers(vector <int> &U);
void getLotteryNumbers(vector <int> &L);
void compareNumbers (const vector<int> &U,const vector<int> &L);
int main()
{
char response = 'Y';
do {
vector <int> user; getUserNumbers(user);
vector <int> lotterynums; getLotteryNumbers(lotterynums);
cout << "Would you like to play again (Y or N) ";
cin >> response;
} while(toupper(response) == 'Y');}
void getUserNumbers(vector <int> &U)
{
int digits;
int userint;
const int SIZE = 5;
cout << "Please enter five digits in the range 0 to 9: " << endl;
for (int i=0;i<SIZE;i++)
{
do {
cin >> digits;
U.push_back (digits);
} while (digits < 0 || digits > 9); }}
void getLotteryNumbers(vector <int> &L)
{
int randnums; const int SIZE = 5;
for(int i=0; i<SIZE; i++)
{
randnums = rand() % 9;
L.push_back (randnums); }
}
void compareNumbers (const vector<int> &U,const vector<int> &L)
{
}
Explanation / Answer
You only need to implement the compareNumbers function:
//////////////////////////////////////////////////////
void compareNumbers (const vector<int> &U,const vector<int> &L)
{
int count = 0 ;
const int Size = 5 ;
for (int i = 0; i < Size; i++)
{
if (U[i] == L[i])
count++ ;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.