Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Not sure how to create this function ---> void initRaffle(int raffles[MAXRAFFLE]

ID: 3937995 • Letter: N

Question

Not sure how to create this function ---> void initRaffle(int raffles[MAXRAFFLE]);

The paramters are:

Pre-conditions: raffles is the collection of all possible raffle tickets

Post-condition: Each raffle ticket should have a default owner number that indicates it has not been sold yet What to do in this function: Each index number represents a different ticket number for the Raffle. The value in the array at that index is the ticket's owner (an index that represents a person at the Fundraising Gala). Initialize all the values in the array to a integer that indicates

Context is listed below:

#include <stdio.h>
#include <string.h>

//Constants to be used.
//MAXSIZE is the maximum size of all strings
//MAXAUCTIONITEMS is the maximum number of items in the auction
//MAXRAFFLE is the maximum number of available raffle tickets
#define MAXSIZE 100
#define MAXAUCTIONITEMS 1000
#define MAXRAFFLE 1000

//Function prototypes - do not change these
void initRaffle(int raffles[MAXRAFFLE]);
void initAuction(float auction[2][MAXAUCTIONITEMS]);
void buyTickets(float * totalRevenue, int * ticketsSold, int numTickets, float price);
void buyRaffle(float * totalRevenue, int raffles[MAXRAFFLE], int availTickets, int numTickets, int person);
void bid(float auction[2][MAXAUCTIONITEMS], float bid, int auctionNumber, int person, int flag);
float awardAuction(float auction[2][MAXAUCTIONITEMS], int auctionNumber);
void awardRaffle(int raffles[MAXRAFFLE], int raffleNumber, int winner);

//Main function
int main() {
FILE * ifp;
char filename[MAXSIZE], event[MAXSIZE], item[MAXSIZE];
float presale, dayOf, totalRevenue = 0;
float auctions[2][MAXAUCTIONITEMS];
int raffles[MAXRAFFLE];
int numPresale, numAuctions, numRaffle, numPrizes, numEvents;
int i, ticketsSold = 0, auctionFlag = 1;

printf("Please enter the input file name. ");
scanf("%s", filename);

ifp = fopen(filename, "r");

fscanf(ifp, "%f%f%d", &presale, &dayOf, &numPresale);

totalRevenue += numPresale * presale;
ticketsSold = numPresale;

fscanf(ifp, "%d", &numAuctions);
fscanf(ifp, "%d%d", &numRaffle, &numPrizes);
fscanf(ifp, "%d", &numEvents);

initRaffle(raffles);
initAuction(auctions);

for (i=0; i<numEvents; i++) {
fscanf(ifp, "%s", event);

if (strcmp(event, "BUY") == 0) {
fscanf(ifp, "%s", item);
if (strcmp(item, "TICKET") == 0) {
int numTickets;
fscanf(ifp, "%d", &numTickets);
buyTickets(&totalRevenue, &ticketsSold, numTickets, dayOf);
}
else if (strcmp(item, "RAFFLE") == 0){
int numTickets, person;
fscanf(ifp, "%d%d", &numTickets, &person);
buyRaffle(&totalRevenue, raffles, numRaffle, numTickets, person);
}
}
else if (strcmp(event, "BIDITEM") == 0) {
int itemNumber, person;
float amount;
fscanf(ifp, "%d%d%f", &itemNumber, &person, &amount);
bid(auctions, amount, itemNumber, person, auctionFlag);
}
else if (strcmp(event, "CLOSEAUCTION") == 0) {
printf("CLOSE AUCTION. ");
auctionFlag = 0;
}
else if (strcmp(event, "AWARD") == 0) {
fscanf(ifp, "%s", item);
if (strcmp(item, "AUCTION") == 0) {
int auctionNumber;
fscanf(ifp, "%d", &auctionNumber);
totalRevenue += awardAuction(auctions, auctionNumber);
}
else if (strcmp(item, "RAFFLE") == 0){
int raffleNumber, winner;
fscanf(ifp, "%d%d", &raffleNumber, &winner);
awardRaffle(raffles, raffleNumber, winner);
}
}
else {
printf("TOTALREVENUE is $%.2lf. ", totalRevenue);
}
}

fclose(ifp);
return 0;
}

Explanation / Answer

// Pre-conditions: raffles is the collection of all possible raffle tickets
// Post-condition: Each raffle ticket should have a default owner number
// that indicates it has not been sold yet
//
// What to do in this function: Each index number represents a different
// ticket number for the Raffle. The value in the array at that index is
// the ticket's owner (an index that represents a person at the Fundraising
// Gala). Initialize all the values in the array to a integer that indicates
// the ticket has not been sold yet.
void initRaffle(int raffles[MAXRAFFLE]) {
int i;
for(i=0; i<MAXRAFFLE; i++)
raffles[i] -= 1;
return;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote