Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Program will not compile

0 votes
asked Oct 28, 2019 by anonymous
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

void getNumbers(int[], const int);
void generateRndNumbers(int[], const int);
int compareNumbers(const int[], const int[], int[], const int);
void displayResult(const int[], const int[], int[], const int, int);

/* **********************************************************
   Definition: getNumbers

   This function accepts the following array as its argument:

      * user[]

   It asks for five lotto numbers from the user and stores
   these in the array.
   ********************************************************** */

void getNumbers(int user[], int numbers)
{
    /* Get number (loop counter) */
    int getNum = 0;

    /* Ask for the numbers */
    for (getNum = 0; getNum < numbers; getNum++)
    {
        cout << "Please enter number " << (getNum + 1) << ": ";
        cin >> user[getNum];

        /* Validate input */
        while (user[getNum] < 0 || user[getNum] > 9)
        {
            cout << "Please enter number " << (getNum + 1) << ": ";
            cin >> user[getNum];
        }
    }
    cout << endl;
}

/* **********************************************************
   Definition: generateRndNumbers

   This accepts the following array as its argument:

      * lottery[]

   It generates and stores in each subscript a random number
   in the range of 1 through 9.
   ********************************************************** */

void generateRndNumbers(int lottery[], const int numbers)
{
    /* Constants: Highest number, Lowest number */
    const int HIGHEST = 9,
        LOWEST = 1;

    /* Seed the random number generator */
    srand((unsigned int)time(NULL));

    /* Variable: Count (loop counter) */
    int cnt = 0;

    while (cnt < numbers)
    {
        lottery[cnt] = (rand() % (HIGHEST - LOWEST + 1)) + LOWEST;
        cnt++;
    }
}

/* **********************************************************
   Definition: compareNumbers

   This function accepts the following arrays as argument:

      * user[]
      * lottery[]
      * result[]

   It compares the numbers entered by the user with those
   randomly generated. The matching numbers are then stored
   in result[] and further processed.
   ********************************************************** */

int compareNumbers(const int lottery[], const int user[], int result[],
    const int size)
{
    /* Variable: Count (counter variable) */
    int count = 0;

    /* The ternary in this loop compares user[] to lottery[], and if there is a match
       between both, result[] gets the matching numbers */
    for (int compare = 0; compare < size; compare++)
    {
        user[compare] == lottery[compare] ? result[compare] = user[compare] :
            user[compare];

        if (result[compare] == lottery[compare])
        {
            count += 1;
        }
    }

    /* Return: count */
    return count;
}

/* **********************************************************
   Definition: displayResult

   This function accepts the following arrays as argument:

      * lottery[]
      * user[]
      * result[]

   It displays the result of each drawing.
   ********************************************************** */
void displayResult(const int lottery[], const int user[], int result[],
    const int size, int count)
{
    /* Variables: User numbers, Lottery numbers, Result numbers (loop
                  counters */
    int uNum = 0,
        rNum = 0,
        lNum = 0;

    /* Display: The numbers entered by the user */
    cout << "\nYou entered: " << setw(6) << right;
    for (uNum = 0; uNum < size; uNum++)
    {
        cout << user[uNum] << " ";
    }

    /* Display: The drawn numbers */
    cout << "\nDrawn numbers: " << setw(4) << right;
    for (lNum = 0; lNum < size; lNum++)
    {
        cout << lottery[lNum] << " ";
    }
    cout << endl;

    /* The ternary in this loop determines whether the number stored
    is greater 0, and if so these numbers will be displayed if there
    are any. If there are no matching numbers, - will be displayed in
    their place */
    cout << "Matching numbers: ";
    for (rNum = 0; rNum < size; rNum++)
    {
        result[rNum] > 0 ? cout << (result[rNum]) << " " : cout << "- ";
        result[rNum] = 0;
    }
    cout << endl << endl;

    /* If all numbers match up the winner is congratulated */
    if (count == size)
    {
        cout << "\nWINNER! ALL NUMBERS MATCH!\n";
    }
}

1 Answer

0 votes
answered Oct 28, 2019 by gameforcer (2,990 points)

You didn't include library required for setw and your program does not have main function. Add these to your program in appropriate places:

#include <iomanip>

int main()
{
    return 0;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...