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

Can someone help me find the errors in my codes and fix them... There are mistak

ID: 3935376 • Letter: C

Question

Can someone help me find the errors in my codes and fix them... There are mistakes on the raffle portions. These are my codes so far:

NOTE: Only use void functions if possible, please...

#include <stdio.h>

#include <string.h>

//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;

}

// 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;

}

// Pre-conditions: auction is the collection of all possible auction items

// Post-condition: Each auction should have a default price of 0 and a default

// bidder number that indicates it has not been bid on yet

//

// What to do in this function: Each index number represents a different

// auction item for the Raffle. Select one row of the two-dimensional

// array to be for bids; the other row will be for people (the current highest

// bidder). Initialize all bids to zero and initialize all people to a number

// that indicates the item has not been bid on yet

void initAuction(float auction[2][MAXAUCTIONITEMS]) {

int i;

for (i=0;i<MAXAUCTIONITEMS;i++) {

auction [0][i] = 0;

auction [1][i] =- 1;

}

}

// Pre-conditions: totalRevenue is a pointer to the total amount that the Gala has earned

// ticketsSold is a pointer to the current number of tickets sold

// numTickets is the number of tickets that the person would like to purchase

// price is the current cost of the tickets (the DayOf price)

// Post-condition: Sells numTickets to the current person at price and updates the number

// of tickets sold and the current total revenue

//

// What to do in this function: Calculate the cost of the tickets and add it to the total

// revenue. Print out the ticket numbers that were sold to the screen. Update the number

// of tickets that have been sold.

void buyTickets(float * totalRevenue, int * ticketsSold, int numTickets, float price) {

*totalRevenue += numTickets * price;

printf (" SOLD TICKET %d - %d", *ticketsSold, (*ticketsSold+numTickets)-1);

*ticketsSold += numTickets;

}

// Pre-conditions: totalRevenue is a pointer to the total amount that the Gala has earned

// raffles is an array of all possible raffle tickets

// availTickets is the number of raffle tickets available to be sold

// numTickets is the number of raffle tickets that the person would like to purchase

// person is the numerical identifier of the person attempting to buy tickets

// Post-condition: Sells numTickets to the current person if tickets are available, or sells as

// as many as are left, or sells none if no tickets are left. Updates totalRevenue

// if any tickets are sold. Each ticket sells for $2

//

// What to do in this function: The value stored in each index of raffles should be the number of the

// person that bought that ticket. For example if person 35 holds raffle tickets 11-15, then elements 11-15

// of raffles should all be equal to 35.

//

// Traverse to the next available ticket in the raffles array, if it exists. If it does not exist, print

// out that no tickets will be given to this person. If it does exist, check to see if there are enough

// tickets left for the person to get the full number they are looking for. If there are not enough for

// the full amount, give them all the tickets that are left. Print out which tickets they are given.

// Update totalRevenue with the number of tickets sold at $2 each.

void buyRaffle(float * totalRevenue, int raffles[MAXRAFFLE], int availTickets, int numTickets, int person) {

int id=0;

if(numTickets<availTickets) {

int i;

for(i=0;i<MAXRAFFLE;i++) {

if(raffles[i]==-1) {

if(i+numTickets-1<MAXRAFFLE) {

for(id=i;id<numTickets;id++) {

raffles[id]=person;

}

printf(" RAFFLE TICKETS %d - %d given to PERSON %d", i,(i+numTickets-1), person);

*totalRevenue+= numTickets*2;

return;

}

else {

id=i;

while(id<MAXRAFFLE) {

raffles[id]=person;

id++;

}

printf(" RAFFLE TICKETS %d - %d given to PERSON %d", id,(MAXRAFFLE-i-1), person);

*totalRevenue += (MAXRAFFLE-i-1)*2;

return;

}

}

}

}

printf(" NO RAFFLE TICKETS given to PERSON %d", person);

}

// Pre-conditions: auction is an 2D array that holds the current highest bid and the person with

// the highest bid

// bid is a new proposed bid

// auctionNumber is the numerical identifier for the item being bid on

// person is the numerical identifier of the person attempting to bid

// flag is a value that indicates whether or not bids are still being accepted

// Post-condition: Updates the auctions with a new high bid if present

// Will not accept new bids that are not higher than old bids

// Will not accept new bids if the auctions are closed

//

// What to do in this function: Check to see if the auctions are still open based on flag

//

// If bids are still being accepted, check to see if bid is higher than the current bid for

// the auction. If it is higher, update the auction with the new bid and the new person number

// Print out the result of either accepted or rejected

void bid(float auction[2][MAXAUCTIONITEMS], float bid, int auctionNumber, int person, int flag) {

if(flag) {

if(bid>auction[0][auctionNumber]) {

auction[0][auctionNumber]=bid;

auction[1][auctionNumber]=person;

printf(" BIDITEM %d ACCEPTED for PERSON %d at %0.2f DOLLARS",auctionNumber,person, bid);

}

else {

printf(" BIDITEM %d REJECTED for PERSON %d at %0.2f DOLLARS",auctionNumber,person, bid);

}

}

else

printf(" BIDITEM %d REJECTED for PERSON %d at %0.2f DOLLARS",auctionNumber,person, bid);

}

// Pre-conditions: auction is an 2D array that holds the current highest bid and the person with

// the highest bid

// auctionNumber is the numerical identifier for the item being awarded

// Post-condition: Returns the value of the highest bid for the auction specified by auction number

//

// What to do in this function: Check to see if the auction identified by auctionNumber has any

// bids. If so, award the auction to the person with the highest bid. If not, print out that

// there have been no bids for this item. Return the appropriate value to be added to totalRevenue

float awardAuction(float auction[2][MAXAUCTIONITEMS], int auctionNumber) {

if(auction[0][auctionNumber]!= EOF) {

printf(" AUCTION ITEM %d WON BY PERSON %.2f for $%.2f",auctionNumber, auction[1][auctionNumber],auction[0][auctionNumber]);

return auction[0][auctionNumber];

}

printf(" NO BIDS FOR AUCTION ITEM %d", auctionNumber);

return 0;

}

// Pre-conditions: raffles is an array of all possible raffle tickets

// winner is the winning ticket number

// raffleNumber is the current raffle being held

//

// Post-condition: prints out the numerical identifier of the person who

// holds the winning ticket number

void awardRaffle(int raffles[MAXRAFFLE], int raffleNumber, int winner) {

while (raffles[winner] != EOF) {

printf (" RAFFLE %d WON BY PERSON %d", raffleNumber,raffles[winner]);

break;

}

}

INPUT:

15 25 200

3

100 4

27

BUY TICKET 8

BUY RAFFLE 30 22

BIDITEM 0 2 5

BIDITEM 0 3 20

BUY TICKET 10

BUY RAFFLE 40 209

BUY TICKET 1

BIDITEM 1 17 50

BIDITEM 2 5 30

BUY RAFFLE 26 123

BUY TICKET 3

BIDITEM 1 16 65

BUY RAFFLE 19 211

BIDITEM 1 17 70

BIDITEM 2 200 45

BIDITEM 2 201 54

BUY RAFFLE 1 27

CLOSEAUCTION

BIDITEM 1 100 10000

AWARD RAFFLE 0 13

AWARD RAFFLE 1 98

AWARD RAFFLE 2 30

AWARD RAFFLE 3 85

AWARD AUCTION 0

AWARD AUCTION 1

AWARD AUCTION 2

TOTAL REVENUE

CORRECT OUTPUT:

SOLD TICKETS 200 - 207

RAFFLE TICKETS 0 - 29 given to PERSON 22

BIDITEM 0 ACCEPTED for PERSON 2 at 5.00 DOLLARS

BIDITEM 0 ACCEPTED for PERSON 3 at 20.00 DOLLARS

SOLD TICKETS 208 - 217

RAFFLE TICKETS 30 - 69 given to PERSON 209

SOLD TICKETS 218 - 218

BIDITEM 1 ACCEPTED for PERSON 17 at 50.00 DOLLARS

BIDITEM 2 ACCEPTED for PERSON 5 at 30.00 DOLLARS

RAFFLE TICKETS 70 - 95 given to PERSON 123

SOLD TICKETS 219 - 221

BIDITEM 1 ACCEPTED for PERSON 16 at 65.00 DOLLARS

RAFFLE TICKETS 96 - 99 given to PERSON 211

BIDITEM 1 ACCEPTED for PERSON 17 at 70.00 DOLLARS

BIDITEM 2 ACCEPTED for PERSON 200 at 45.00 DOLLARS

BIDITEM 2 ACCEPTED for PERSON 201 at 54.00 DOLLARS

NO RAFFLE TICKETS given to PERSON 27

CLOSEAUCTION

BIDITEM 1 REJECTED for PERSON 100 at 10000.00 DOLLARS

RAFFLE 0 WON BY PERSON 22

RAFFLE 1 WON BY PERSON 211

RAFFLE 2 WON BY PERSON 209

RAFFLE 3 WON BY PERSON 123

AUCTION ITEM 0 WON BY PERSON 3 for $20.00

AUCTION ITEM 1 WON BY PERSON 17 for $70.00

AUCTION ITEM 2 WON BY PERSON 201 for $54.00

TOTALREVENUE is $3894.00

Explanation / Answer

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

//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;
}

// 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;
}

// Pre-conditions: auction is the collection of all possible auction items
// Post-condition: Each auction should have a default price of 0 and a default
// bidder number that indicates it has not been bid on yet
//
// What to do in this function: Each index number represents a different
// auction item for the Raffle. Select one row of the two-dimensional
// array to be for bids; the other row will be for people (the current highest
// bidder). Initialize all bids to zero and initialize all people to a number
// that indicates the item has not been bid on yet

void initAuction(float auction[2][MAXAUCTIONITEMS]) {
int i;
for (i=0;i<MAXAUCTIONITEMS;i++) {
auction [0][i] = 0;
auction [1][i] =- 1;
}
}

// Pre-conditions: totalRevenue is a pointer to the total amount that the Gala has earned
// ticketsSold is a pointer to the current number of tickets sold
// numTickets is the number of tickets that the person would like to purchase
// price is the current cost of the tickets (the DayOf price)
// Post-condition: Sells numTickets to the current person at price and updates the number
// of tickets sold and the current total revenue
//
// What to do in this function: Calculate the cost of the tickets and add it to the total
// revenue. Print out the ticket numbers that were sold to the screen. Update the number
// of tickets that have been sold.

void buyTickets(float * totalRevenue, int * ticketsSold, int numTickets, float price) {
*totalRevenue += numTickets * price;
printf (" SOLD TICKET %d - %d", *ticketsSold, (*ticketsSold+numTickets)-1);
*ticketsSold += numTickets;
}

// Pre-conditions: totalRevenue is a pointer to the total amount that the Gala has earned
// raffles is an array of all possible raffle tickets
// availTickets is the number of raffle tickets available to be sold
// numTickets is the number of raffle tickets that the person would like to purchase
// person is the numerical identifier of the person attempting to buy tickets
// Post-condition: Sells numTickets to the current person if tickets are available, or sells as
// as many as are left, or sells none if no tickets are left. Updates totalRevenue
// if any tickets are sold. Each ticket sells for $2
//
// What to do in this function: The value stored in each index of raffles should be the number of the
// person that bought that ticket. For example if person 35 holds raffle tickets 11-15, then elements 11-15
// of raffles should all be equal to 35.
//
// Traverse to the next available ticket in the raffles array, if it exists. If it does not exist, print
// out that no tickets will be given to this person. If it does exist, check to see if there are enough
// tickets left for the person to get the full number they are looking for. If there are not enough for
// the full amount, give them all the tickets that are left. Print out which tickets they are given.
// Update totalRevenue with the number of tickets sold at $2 each.

void buyRaffle(float * totalRevenue, int raffles[MAXRAFFLE], int availTickets, int numTickets, int person) {
int id=0;

if(numTickets<availTickets) {
int i;
for(i=0;i<MAXRAFFLE;i++) {
if(raffles[i]==-1) {
if(i+numTickets-1<MAXRAFFLE) {
for(id=i;id<numTickets;id++) {
raffles[id]=person;
}
printf(" RAFFLE TICKETS %d - %d given to PERSON %d", i,(i+numTickets-1), person);
*totalRevenue+= numTickets*2;
return;
}
else {
id=i;
while(id<MAXRAFFLE) {
raffles[id]=person;
id++;
}
printf(" RAFFLE TICKETS %d - %d given to PERSON %d", id,(MAXRAFFLE-i-1), person);
*totalRevenue += (MAXRAFFLE-i-1)*2;
return;
}
}
}
}
printf(" NO RAFFLE TICKETS given to PERSON %d", person);
}

// Pre-conditions: auction is an 2D array that holds the current highest bid and the person with
// the highest bid
// bid is a new proposed bid
// auctionNumber is the numerical identifier for the item being bid on
// person is the numerical identifier of the person attempting to bid
// flag is a value that indicates whether or not bids are still being accepted
// Post-condition: Updates the auctions with a new high bid if present
// Will not accept new bids that are not higher than old bids
// Will not accept new bids if the auctions are closed
//
// What to do in this function: Check to see if the auctions are still open based on flag
//
// If bids are still being accepted, check to see if bid is higher than the current bid for
// the auction. If it is higher, update the auction with the new bid and the new person number
// Print out the result of either accepted or rejected

void bid(float auction[2][MAXAUCTIONITEMS], float bid, int auctionNumber, int person, int flag) {
if(flag) {
if(bid>auction[0][auctionNumber]) {
auction[0][auctionNumber]=bid;
auction[1][auctionNumber]=person;
printf(" BIDITEM %d ACCEPTED for PERSON %d at %0.2f DOLLARS",auctionNumber,person, bid);
}
else {
printf(" BIDITEM %d REJECTED for PERSON %d at %0.2f DOLLARS",auctionNumber,person, bid);
}
}
else
printf(" BIDITEM %d REJECTED for PERSON %d at %0.2f DOLLARS",auctionNumber,person, bid);
}

// Pre-conditions: auction is an 2D array that holds the current highest bid and the person with
// the highest bid
// auctionNumber is the numerical identifier for the item being awarded
// Post-condition: Returns the value of the highest bid for the auction specified by auction number
//
// What to do in this function: Check to see if the auction identified by auctionNumber has any
// bids. If so, award the auction to the person with the highest bid. If not, print out that
// there have been no bids for this item. Return the appropriate value to be added to totalRevenue

float awardAuction(float auction[2][MAXAUCTIONITEMS], int auctionNumber) {
if(auction[0][auctionNumber]!= EOF) {

printf(" AUCTION ITEM %d WON BY PERSON %.2f for $%.2f",auctionNumber, auction[1][auctionNumber],auction[0][auctionNumber]);

return auction[0][auctionNumber];

}

printf(" NO BIDS FOR AUCTION ITEM %d", auctionNumber);

return 0;
}

// Pre-conditions: raffles is an array of all possible raffle tickets
// winner is the winning ticket number
// raffleNumber is the current raffle being held
//
// Post-condition: prints out the numerical identifier of the person who
// holds the winning ticket number

void awardRaffle(int raffles[MAXRAFFLE], int raffleNumber, int winner) {
while (raffles[winner] != EOF) {
printf (" RAFFLE %d WON BY PERSON %d", raffleNumber,raffles[winner]);
break;
}
}

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