Question

Write a c program that generates the numerical lottery.You have to define an array of 500x6....

Write a c program that generates the numerical lottery.You have to define an array of 500x6. Here are 6 blocks. There are numbers between 1-49 in each block. (1 and 49 included.) The ball is drawn from each block. (1 ball selection from each block) you get everyone's guess.This array table is estimated by 500 people(everyone pulls 6 balls).Then you fill this array with the random function. Then you define an array of 1x6. (This is the numbers of the balls at the end of the draw.) You have to fill this with the rand function.You fill out with the predictions, then you write a function that compares the result.Like how many people know 1 ball, how many people know two balls ….. Then you file them.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <stdlib.h>

// helper method to check if a num exist in array 
// of size, so that we don't put duplicate balls
int indexOf(int arr[], int num, int size) {
    int i=0;
    for(i=0; i<size; i++) {
        if(arr[i] == num) {
            return i;
        }
    }
    return -1;
}

void fillGuesses(int guessLine[], int size) {
    int i=0;

    while(i != size) {
        // fill at i th position
        int guess = rand() % 49 + 1;
        while(indexOf(guessLine, guess, i) != -1) {
            guess = rand() % 49 + 1;
        }
        guessLine[i++] = guess;
    }
}

// Helper function to print guesses if required
void printArr(int arr[], int size) {
    int i;
    for(i=0; i<size; i++) {
        printf("%d ", arr[i]);
    }
    printf("
");
}

int main(void) {
    int i;

    // 500 people make guesses with 6 balls
    int guesses[500][6];
    int draw[6];

    // fill guesses with rand function
    for(i=0; i<500; i++) {
        fillGuesses(guesses[i], 6);
        //printArr(guesses[i], 6);
    }

    // fill the final draw of balls
    fillGuesses(draw, 6);

    // Array to hold how many people guess balls correctly
    // count[i] tells number of people who guess i balls 
    // correctly out of 6 balls.
    int counts[7] = {0};

    for(i=0; i<500; i++) {
        int correct = 0;
        int j;

        for(j=0; j<6; j++) {
            if(indexOf(draw, guesses[i][j], 6) != -1) {
                correct++;
            }
        }

        counts[correct] += 1;
    }

    for(i=1; i<=6; i++) {
        printf("Number of people guessing %d balls correctly: %d
", i, counts[i]);
    }


    printf("
");
    return 0;
}


Please upvote, as i have given the exact answer as asked in question. Still in case of any concerns in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
Write a c program that generates the numerical lottery.You have to define an array of 500x6....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program that generates and prints 24 random values using an array and the...

    C++ Write a program that generates and prints 24 random values using an array and the rand () function. Implement an algorithm to find the maximum and a minimum number of random numbers generated. Use the header "#include <ctime>", "#include <cstdlib>" in addition to the usual header: "#include <iostream>"

  • Write a C program that deal with employees’ salaries in a company, as follows: Define an...

    Write a C program that deal with employees’ salaries in a company, as follows: Define an integer array named salaries of size 100 Initialize all array elements with zeros Fill all array elements with random numbers within a range of 350 until 3000 (all inclusive) by using built-in-function rand() and srand() Develop the following functions and call them from the main program: avgSalary(), a function that receives the array and its size as parameters and returns the average salary in...

  • Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...

    Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...

  • C++ C++ Write a program to input eight integer numbers into an array named grade. As...

    C++ C++ Write a program to input eight integer numbers into an array named grade. As each number is input, add the number into a total. After all numbers are input, display the numbers and their average. (You can use cin to take number or use rand() to assign random numbers to the array.)

  • 7eatng that function Write a C++ program that does the following: Fill an array of 123...

    7eatng that function Write a C++ program that does the following: Fill an array of 123 elements using srand) and rand) with random numbers between 150 and 667. Fill an array of 123 elements with random numbers between 150 and 667. Using a loop. Fill an array of 123 elements with random numbers between 150 and 667. Using a for loop Use a void function to fill an array of 123 elements with random numbers between 150 and 667, Possible...

  • C- PROGRAMMING PROJECT #4 Design and Write a C program to calculate an average of an...

    C- PROGRAMMING PROJECT #4 Design and Write a C program to calculate an average of an array of numbers and produce the following output: 1. Your first and last name 2. Course Number 3. C Project Number 4. All the numbers in the array 5. The sum of all the numbers in the array 6. The count of all the numbers in the array 7. The average of all the numbers in the array Double-space after lines 3, 4, 5,...

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • Write a program that performs the following operations on a one dimensional array with 50 unsigned...

    Write a program that performs the following operations on a one dimensional array with 50 unsigned integers. The main program will initialize the array, print the array values to the screen and then call a function that will determine and print the maximum and minimum values. •Declare the array and any other variables. •Use a loop to initialize the array with 50 random integer values between 0 and 99 using the rand() function. (number = rand() % 100;) •Using cout...

  • C++. Write a program that copies the contents of one array into another array but in...

    C++. Write a program that copies the contents of one array into another array but in reverse order using pointers.           - in main()                    - define 2 arrays of type int, 10 elements each                              - initialize one array with numbers 1 through 10                              - initialize all elements of the second array to 0                    - call function reverseCopy with both arrays as arguments                    - display the values of array number 2 (reversed order)           - reverseCopy...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT