16.5k views
3 votes
Make a C program that simulates a teddy bear raffle where you

have a list of up to 50 tickets with the names of the participants
who bought a ticket from you and the ticket number.
ticket number. Create an array of size 50 of type ticket where each element stores the name of the participant and the ticket number.
of the participant and the ticket number they purchased. If there are tickets that were not purchased, in the participant's name place
If there are tickets that were not purchased, place "Unassigned" in the participant's name.
Create a program that randomly generates the number drawn from the raffle, searches for it in the participant array and displays the name of the participant.
and displays the name of the winner. If the drawn number has not been assigned to
a participant, it generates another number until there is a winner.
For the search it uses the indexed search algorithm and as a second search it applies binary search.

2 Answers

5 votes

Final answer:

The College-level task is to develop a C program that simulates a teddy bear raffle. In this simulation, up to 50 participants with assigned ticket numbers are stored in an array, and the program locates the winner using random number generation and search algorithms.

Step-by-step explanation:

C Program for a Teddy Bear Raffle Simulation

This program simulates a raffle with a list of participants. Each participant has a ticket with their name and a ticket number stored in an array of tickets, structured with a maximum size of 50. The program uses random number generation to select a winning ticket and employs both indexed and binary search algorithms to find the winner's name from the list. If a generated ticket number is unassigned, the program will continue to generate numbers until a winner with an assigned ticket is found.

It is important to note that the array must be sorted for the binary search to function properly. The program provides an efficient and systematic method to simulate a raffle and determine a winner among the participants.

User Obey
by
8.2k points
3 votes

Final answer:

To simulate a teddy bear raffle in C, you can create an array of size 50 to store the participants' names and ticket numbers. Generate a random number for the raffle draw and use the indexed search algorithm to find the winner's name in the array. If the drawn number is unassigned, repeat the process.

Step-by-step explanation:

Pseudocode for the program:

1. Define an array of size 50 called 'tickets' to store the participants' names and ticket numbers.
2. Initialize all elements of the 'tickets' array with the value 'Unassigned'.
3. Generate a random number for the raffle draw.
4. Use the indexed search algorithm to find the winner's name corresponding to the drawn number in the 'tickets' array.
5. If the drawn number is not assigned to any participant, repeat step 3 and 4.
6. Once a winner's name is found, display the name.
7. If desired, apply binary search as a second search method to find the winner's name in the 'tickets' array.
8. End the program.

The program starts by creating an array of size 50 to store the participants' names and ticket numbers. Initially, all elements of the array are set to 'Unassigned'.

The program then generates a random number for the raffle draw and uses the indexed search algorithm to find the corresponding participant's name in the array. If the drawn number is not assigned to any participant, the program repeats the process until a winner's name is found.

Once a winner's name is found, it is displayed. The program can also apply binary search as a secondary search method to find the winner's name in the array if desired.

User Dheeraj Bhaskar
by
8.8k points