Need help with my CProject Objective To learn how to write f

Need help with my C-Project...

Objective

To learn how to write functions given specifications

To learn how to the use pass by value and pass by reference variables

To practice planning and implementing complex programs.

Introduction: Programmers for a Better Tomorrow

Programmers for a Better Tomorrow is an organization dedicated to helping charities, medical societies, and scholarship organizations manage various tasks so that they can focus on making the world a better place! They have asked you and your classmates to help them develop some new programs to benefit their organizations.

Problem: Charity Gala (gala.c)

Many charities support good causes, but one of the difficulties each of them has is organizing their fundraising events. You\'ve decided that you\'d like to donate your skills to create a program that organizes the typical activities at a fund-raising gala. In particular, your program will help manage the following:

1) Ticket sales

2) Silent Auction

3) Raffle

Your program will log the number of tickets sold both in advance and at the event, a silent auction for donated items, and a raffle for other donated items.

Program Details

Ticket Sales Details

You will sell tickets in advance and at the door. Prices for buying in advance and at the door will be given. Also, the total number of tickets sold in advance will be given. Each guest will have a unique number. If there are n tickets sold in advance, then these guests will be numbered 0 through n-1. As the event starts, requests to buy tickets at the door may be made and these guests will be numbered sequentially, starting at the lowest unassigned number. The maximum number of guests will be 1000.

Silent Auction Details

The silent auction will have up to 1000 items. At any time, users can bid on any item, so long as the new bid exceeds the previous bid. At the point in time when the auction is closed, the items with at least one bid are given to the users who have placed the highest bid on that item. Your program must always keep track of all of the best bids on items so that no matter when the auction closes, you\'ll have all the data for who has won all of the items. Any item without a bid goes to no one.

Raffle Details

There will be a given number for the total number of raffle tickets sold, that will be 1000 or fewer. Guests can buy raffle tickets for a set price of $2.00. There will be a number of prizes awarded from the raffle (not to exceed 100) after the raffle has finished. For each raffle ticket, you\'ll have to keep track of which guest has it. The raffle tickets will be numbered starting at 0 through the number of tickets minus one. After the raffle finishes, you will be given the raffle numbers pulled for the winners of each prize. You will be guaranteed that these numbers correspond to numbers that were previously handed out during the raffle. You must determine who wins each prize.

Information for each event is provided from a file. You will take in input from the file and produce output for each event that occurs, in order.

A skeleton of the solution for this assignment is posted on the webcourse. You must fill in the functions that are currently empty. After you write each function, you should test it before moving on. The main function should not be modified for the final submission (you may modify it during testing, as long as you return it to its initial form).

Descriptions of each function are given in the skeleton along with the function Pre- and Post-conditions. The output sample on the webcourse shows the wording you should use and how the program should run when completed. Points are allotted for following the precise wording shown.

Input Specification

The first line of the file contains the following three values, separated by spaces:

Cost of the presales tickets (in dollars), Cost of the tickets at the door (in dollars), and the number of presale tickets. The first two values will be positive real numbers to two decimal places and the last will be a positive integer.

The second line of the file will contain one positive integer representing the number of auction items.

The third line of the file will contain the two following positive integers pertaining to the raffle: the number of raffle tickets available and the number of raffle prizes.

The fourth line of the file will contain a single positive integer, numEvents, representing the number of events that occur at the fundraising event. These events are split into two groups: actions by guests at the ball and awards given (raffle, auction, person, totalrevenue). All of the actions precede all of the awards.

The following numEvents lines will contain information about each event that occurs, with one event or award described for each line.

You will produce exactly one line of output for each event described. Here are the formats of each event that could occur:

If a patron buys a ticket at the door, a command will be on a line by itself:

BUY TICKET k

where k is a positive integer indicating the number of tickets bought at the door. These guests will be numbered as previously mentioned. You are guaranteed that the total number of tickets bought, including presales, will not exceed 1000.

If a patron makes a bid in the silent auction, a command of the following form will be issued:

BIDITEM k p d

where k represents the item number for which the bid is being placed, p represents the number of the person placing the bid, and d represents the dollar amount the person has bid. This last value is a positive real number to two decimal places while the others are non-negative integers within the appropriate ranges.

The following command closes the auction. Any bids made after this command is executed are ignored.

CLOSEAUCTION

If a guest desires to buy raffle tickets, a command with the following format will be used:

BUY RAFFLE k p

This command lets person p buy exactly k raffle tickets. The raffle tickets are numbered as previously described, so long as the tickets are still available. If they aren\'t available, the person gets whatever tickets remain.

The last several commands in the file will deal with awarding prizes. These commands will take the following forms.

A query about a raffle item will be of the following form:

AWARD RAFFLE i t

where i is the raffle item being given out and t is the number of the winning ticket of that raffle item. Your program will have to respond with the winner of this item. You will be guaranteed that this query will appear EXACTLY once for each raffle prize and that all queries of this form will appear AFTER the last raffle ticket is sold. Furthermore, you are guaranteed that the raffle ticket number was purchased by an individual and that the raffle prize number is valid. Finally, a single raffle ticket will correspond to at most one raffle prize.

A status query about a silent auction item will be of the following form:

AWARD AUCTION i

where i represents the silent auction item being queried. Your program will have to respond with the winner of this item and the amount they paid for it OR that there were no bids for that item.

The final status query in the file will be the following line:

TOTAL REVENUE

Output Specification

For the input command of the form:

BUY TICKET k

output a single line of the form:

SOLD TICKETS a - b

where a is the starting number of the tickets sold and b is the ending number (inclusive) of the tickets sold. If k is 1, then a and b will be equal. (Note: For the very first command of this type, the value of a will equal the number of presold tickets, since the presale tickets are numbered from 0 to the total number of presale tickets minus 1.)

For the input command of the form:

BIDITEM k p d

output a single line with one of the following forms:

BIDITEM k ACCEPTED for PERSON p at d DOLLARS

BIDITEM k REJECTED for PERSON p at d DOLLARS

The two reasons to reject a bid are if the new bid is not higher than the previous bid OR if the auction has been closed already.

For the CLOSEAUCTION command, simply print a single line with the exact same output:

CLOSEAUCTION

For the input command

BUY RAFFLE k p

output a single line of one of the two following forms:

RAFFLE TICKETS a - b given to PERSON p

NO RAFFLE TICKETS given to PERSON p

where a represents the first raffle ticket number issued and b represents the last raffle ticket number issued to person p. If there are no more raffle tickets left with the command is issued, the latter format is used. Note that the former format may be used if the person asks for a certain number of raffle tickets, but gets fewer since she bought all that were left.

For the input command

AWARD RAFFLE i t

output a single line of the following format:

RAFFLE i WON BY PERSON p

where i is the raffle item in question (in the query) and p is the number of the guest who won the item.

For the input command

AWARD AUCTION i

output a single line of the following format:

AUCTION ITEM i WON BY PERSON p for $d.dd

where i is the number of the auction item, p is the person who won the item and d.dd is the number of dollars he paid for it, to two decimal places. Or, if there are no bids for the item, output a single line of the following format:

NO BIDS FOR AUCTION ITEM %d

For the input command

TOTALREVENUE

output a single line with the following format:

TOTALREVENUE is $d.dd

where d.dd is the total amount gained by the event via ticket sales, auction sales, and raffle ticket sales. (We are assuming that all items were donated so that there was no cost associated with the event.)

Sample Input/Output

Sample input and output files will be provided on the webcourse.

Deliverables

A single source file named gala.c turned in through WebCourses.

Restrictions

Although you may use other compilers, your program must compile in gcc and run in Code::Blocks. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Make sure you include comments throughout your code describing the major steps in solving the problem.

Make sure to use good programming style, including use of appropriate constants, good variable names and good use of white space.

Grading Details

Your programs will be graded upon the following criteria:

1) Your correctness

2) Your programming style and use of white space. Even if you have a plan and your program works perfectly, if your programming style is poor or your use of white space is poor, you could get 10% or 15% deducted from your grade.

3) Compatibility – You must submit C source files that can be compiled and executed in a standard C Development Environment. If your program does not compile, you will get a sizable deduction from your grade.

Input File (gala.txt):

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

Output (gala_out.txt):

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

Scaffold:

/*Header Comment

*/

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

}

// 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]) {

}

// 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]) {

}

// 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) {

}

// 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) {

}

// 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) {

}

// 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) {

}

// 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) {

}

Solution


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

#define MAX_GUESTS 1000
#define MAX_AUCTION_ITEMS 1000
#define MAX_RAFFLE_TICKETS 100000
#define MAX_RAFFLE_PRIZES 100
#define DRINK_KINDS 10
#define COMMAND_SIZE 20

// Structs
typedef struct {
    int numPresaleTickets;
    int ticketNumber;
    float presaleCost;
    float doorCost;
} ticket_sales;

typedef struct {
    int open;
    int numItems;
    int currentWinner[MAX_AUCTION_ITEMS];
    float currentBid[MAX_AUCTION_ITEMS];
    float itemMarketPrice[MAX_AUCTION_ITEMS];
    float minBidIncrement;
} auction_struct;

typedef struct {
    int numTicketsLeft;
    int ticketCost; // int, because the instructions said it is strange to not have a ticket cost in whole dollars
    int numPrizes;
    int ticketIndex;
    int ticketOwner[MAX_RAFFLE_TICKETS];
    float prizeValue[MAX_RAFFLE_PRIZES];
} raffle_struct;

typedef struct {
    int stock[DRINK_KINDS];
    float price[DRINK_KINDS];
} drink_struct;

// Function Prototypes
float buyTicket(FILE *ofp, ticket_sales* tickets, int numSold);
void bidItem(FILE *ofp, auction_struct* auction, int itemNum, int personNum, float bidAmount);
int buyRaffle(FILE *ofp, raffle_struct* raffle, float personNet[], int numSold, int personNumber);
float buyDrink(FILE *ofp, drink_struct* drinks, int numSold, int drinkNumber);
void printRevenue(FILE *ofp, float revenue);
void closeAuction(FILE *ofp, auction_struct* auction);
void initilizeArray(int array[], int length, int value);
void awardRaffle(FILE *ofp, raffle_struct* raffle, float personNet[], int item, int ticketNumber);
void awardPerson(FILE *ofp, ticket_sales* tickets, float personNet[], int ID);
float awardAuction(FILE *ofp, auction_struct* auction, float personNet[], int itemNum);


// Main Function
int main(void){
    // Initilize Variables
    int i, numEvents, k, n, p, t, item, ID; // Variables k, n, p, and t named as per the Program 10 input file format specification. Because i was taken for looping, the specification\'s use of i is replaced by item and ID
    float d; // d represents the dollar amount of a bid, as per the input specification.
    float revenue = 0;
    char command[COMMAND_SIZE];

    // To keep track of a person\'s net gain, we\'ll use this array
    float personNet[MAX_GUESTS];

    // Initilize Structs
    ticket_sales tickets;
    tickets.ticketNumber = 0;
    auction_struct auction;
    auction.open = 1;
    raffle_struct raffle;
    raffle.ticketIndex = 0;
    drink_struct drinks;

    // Open Files
    FILE *ifp;
    ifp = fopen(\"auction.txt\", \"r\"); // There wasn\'t a specific input file name given, so I\'m leaving this as simply \"auction.txt\"
    FILE *ofp;
    ofp = fopen(\"auction.out\", \"w\");


    // Get the first 8 lines of the input file and act on them
    // Ticket info is on line 1
    fscanf(ifp, \"%f%f%d\", &tickets.presaleCost, &tickets.doorCost, &tickets.numPresaleTickets);
    revenue += tickets.presaleCost * tickets.numPresaleTickets; // Add the presale tickets to the total revenue
    tickets.ticketNumber = tickets.numPresaleTickets-1; // Set the current ticket number index

    // Auction info is on lines 2 and 3
    fscanf(ifp, \"%d%f\", &auction.numItems, &auction.minBidIncrement);
    for(i=0; i<auction.numItems; i++)
        fscanf(ifp, \"%f\", &auction.itemMarketPrice[i]);
    // Initilize the auction.currentWinner array so that each item gets set to -1 to indicate no winner.
    initilizeArray(auction.currentWinner, auction.numItems, -1);
    initilizeArray(auction.currentBid, auction.numItems, 0);

    // Raffle info is on lines 4 and 5
    fscanf(ifp, \"%d%d%d\", &raffle.numTicketsLeft, &raffle.ticketCost, &raffle.numPrizes);
    for(i=0; i<raffle.numPrizes; i++)
        fscanf(ifp, \"%f\", &raffle.prizeValue[i]);
    // Initilize the raffle.ticketOwner array so that each ticket is set to -1 to indicate no owner.
    initilizeArray(raffle.ticketOwner, raffle.numTicketsLeft, -1);

    // Drink info is on lines 6 and 7
    for(i=0; i<DRINK_KINDS; i++)
        fscanf(ifp, \"%d\", &drinks.stock[i]);
    for(i=0; i<DRINK_KINDS; i++)
        fscanf(ifp, \"%f\", &drinks.price[i]);

    // Line 8 is the number of events that will come after this line.
    fscanf(ifp, \"%d\", &numEvents);


    // Create outer main loop
    for(i=0; i<numEvents; i++){
        // Get event from file
        fscanf(ifp, \"%s\", command);

        // Check event and run the appropriate function
        if(strcmp(command, \"BUY\") == 0){
            // Could be either TICKET, RAFFLE, or DRINK. Scan in next token and compare.
            fscanf(ifp, \"%s\", command);
            if(strcmp(command, \"TICKET\") == 0){
                fscanf(ifp, \"%d\", &k);
                revenue += buyTicket(ofp, &tickets, k);
            }
            else if(strcmp(command, \"RAFFLE\") == 0){
                fscanf(ifp, \"%d%d\", &k, &p);
                revenue += buyRaffle(ofp, &raffle, personNet, k, p);
            }
            else if(strcmp(command, \"DRINK\") == 0){
                fscanf(ifp, \"%d%d\", &k, &n);
                revenue += buyDrink(ofp, &drinks, k, n);
            }
        }
        else if(strcmp(command, \"BIDITEM\") == 0){
                fscanf(ifp, \"%d%d%f\", &k, &p, &d);
                bidItem(ofp, &auction, k, p, d);
        }
        else if(strcmp(command, \"CLOSEAUCTION\") == 0)
            closeAuction(ofp, &auction);

        else if(strcmp(command, \"AWARD\") == 0){
            fscanf(ifp, \"%s\", command);
            if(strcmp(command, \"RAFFLE\") == 0){
                fscanf(ifp, \"%d%d\", &item, &t);
                awardRaffle(ofp, &raffle, personNet, item, t);
            }
            else if(strcmp(command, \"AUCTION\") == 0){
                fscanf(ifp, \"%d\", &item);
                revenue += awardAuction(ofp, &auction, personNet, item);
            }
            else if(strcmp(command, \"PERSON\") == 0){
                fscanf(ifp, \"%d\", &ID);
                awardPerson(ofp, &tickets, personNet, ID);
            }
        }
        else if(strcmp(command, \"TOTAL\") == 0){
            fscanf(ifp, \"%s\", command);
            if(strcmp(command, \"REVENUE\") == 0)
                printRevenue(ofp, revenue);
        }
    }
    // Since we are done with the files, close them
    fclose(ifp);
    fclose(ofp);

    // Program Completed, so return 0.
    return 0;
}

// Returns the revenue made from buying tickets
float buyTicket(FILE *ofp, ticket_sales* tickets, int numSold){
    int start = tickets->ticketNumber;

    // It was guarenteed that the number of guests won\'t exceed 1000, but it\'s always good to check, just in case.
    if((start+numSold)>=MAX_GUESTS)
        numSold = (MAX_GUESTS-1) - start;

    // Set increase the ticket number by the number of tickets sold.
    tickets->ticketNumber += numSold;

    // Print the output to the file and return to main
    fprintf(ofp, \"SOLD TICKETS %d - %d\ \", start+1, start+numSold);
    return numSold * tickets->doorCost;
}

int buyRaffle(FILE *ofp, raffle_struct* raffle, float personNet[], int numSold, int personNumber){
    int max;

    if(numSold>(raffle->numTicketsLeft))
        numSold = raffle->numTicketsLeft;

    max = raffle->ticketIndex+numSold;
    // Only sell tickets if we have more to sell
    if(raffle->numTicketsLeft>0){
        // Print the first part of the output
        fprintf(ofp, \"RAFFLE TICKETS %d - \", raffle->ticketIndex);

        // Use a while loop instead of the for loop to eliminate unnecessary variables and calculations.
        //for(i=raffle.ticketIndex; i<max; i++){
        while((raffle->ticketIndex)<max){
            raffle->ticketOwner[raffle->ticketIndex] = personNumber;
            raffle->ticketIndex++;
        }

        // Decrease the number of tickets left to sell, since we just sold some
        raffle->numTicketsLeft -= numSold;

        // Print the rest of the output
        fprintf(ofp, \"%d given to PERSON %d\ \", (raffle->ticketIndex)-1, personNumber);

        // Subtract the cost of tickets from the person\'s net gain
        personNet[personNumber] -= numSold * raffle->ticketCost;
        return numSold * raffle->ticketCost;
    }
    else
        fprintf(ofp, \"NO RAFFLE TICKETS given to PERSON %d\ \", personNumber);

    return 0;
}

void awardRaffle(FILE *ofp, raffle_struct* raffle, float personNet[], int item, int ticketNumber){
    int winnerID = raffle->ticketOwner[ticketNumber];
    fprintf(ofp, \"RAFFLE %d WON BY PERSON %d\ \", item, winnerID);

    // Add the net gain to the person
    personNet[winnerID] += raffle->prizeValue[item];
}

void initilizeArray(int array[], int length, int value){
    int i;
    for(i=0; i<length; i++) //////////////////////////// < or <=? Test with printf(\"%d\", auction.currentWinner[auction.numItems]);
        array[i] = value;
}

void printRevenue(FILE *ofp, float revenue){
    fprintf(ofp, \"TOTALREVENUE is $%.2f\ \", revenue);
}

void closeAuction(FILE *ofp, auction_struct* auction){
    auction->open = 0;
    fprintf(ofp, \"CLOSEAUCTION\ \");
}

float buyDrink(FILE *ofp, drink_struct* drinks, int numSold, int drinkNumber){
    // If there aren\'t enough drinks, just sell what\'s left.
    if(numSold > drinks->stock[drinkNumber]){
        numSold = drinks->stock[drinkNumber];
        drinks->stock[drinkNumber] = 0;
    }
    else
        drinks->stock[drinkNumber] -= numSold;

    // Print Outputs and return the profit
    if(numSold == 0)
        fprintf(ofp, \"NO DRINK %d SOLD\ \", drinkNumber);
    else
        fprintf(ofp, \"SOLD %d of DRINK %d\ \", numSold, drinkNumber);

    return numSold * drinks->price[drinkNumber];
}

void bidItem(FILE *ofp, auction_struct* auction, int itemNum, int personNum, float bidAmount){
    if(auction->open){
        // Reject the bid if it is lower than the last bid or if it isn\'t raised by at least auction.minBidIncrement
        if(bidAmount<auction->currentBid[itemNum] || (bidAmount - auction->currentBid[itemNum]) < auction->minBidIncrement)
            fprintf(ofp, \"BIDITEM %d REJECTED for PERSON %d at %.2f DOLLARS\ \", itemNum, personNum, bidAmount);
        else{
            auction->currentBid[itemNum] = bidAmount;
            auction->currentWinner[itemNum] = personNum;
            fprintf(ofp, \"BIDITEM %d ACCEPTED for PERSON %d at %.2f DOLLARS\ \", itemNum, personNum, bidAmount);
        }
    }
    else
        fprintf(ofp, \"BIDITEM %d REJECTED for PERSON %d at %.2f DOLLARS\ \", itemNum, personNum, bidAmount);
}

float awardAuction(FILE *ofp, auction_struct* auction, float personNet[], int itemNum){
    fprintf(ofp, \"AUCTION ITEM %d WON BY PERSON %d for $%.2f\ \", itemNum, auction->currentWinner[itemNum], auction->currentBid[itemNum]);

    // Because they won, give the person a net gain from their prize
    personNet[auction->currentWinner[itemNum]] += auction->itemMarketPrice[itemNum] - auction->currentBid[itemNum];
    // Returns the amount of money gained from the top bid as the profit.
    return auction->currentBid[itemNum];
}

void awardPerson(FILE *ofp, ticket_sales* tickets, float personNet[], int ID){
    // Include their ticket price in the net gain/loss
    // If it was a presale ticket, use that cost. Else use regular cost
    if(ID<tickets->numPresaleTickets)
        personNet[ID] -= tickets->presaleCost;
    else
        personNet[ID] -= tickets->doorCost;

    // Check if the person is up or down, and print the proper result
    if(personNet[ID]>=0)
        fprintf(ofp, \"PERSON %d is UP $%.2f\ \", ID, personNet[ID]);
    else
        fprintf(ofp, \"PERSON %d is DOWN $%.2f\ \", ID, fabs(personNet[ID]));
}


auction.txt

15 25 200
3 10
17.99 22.99 109.99
100 2 4
5.99 99.99 20.00 49.99
10 10 10 10 10 10 10 10 10 10
3.99 5.99 7.99 8.00 5.00 5.00 5.00 6.00 7.00 9.99
38
BUY TICKET 8
BUY RAFFLE 30 22
BIDITEM 0 2 5
BIDITEM 0 3 20
BUY TICKET 10
BUY DRINK 3 6
BUY RAFFLE 40 209
BUY TICKET 1
BIDITEM 1 17 50
BIDITEM 2 5 30
BUY RAFFLE 26 123
BUY TICKET 3
BUY DRINK 5 3
BIDITEM 1 16 65
BUY RAFFLE 19 211
BUY DRINK 2 6
BIDITEM 1 17 70
BUY DRINK 6 3
BIDITEM 2 200 45
BUY DRINK 9 0
BUY DRINK 7 3
BIDITEM 2 201 54
BUY RAFFLE 1 27
CLOSEAUCTION
BUY DRINK 1 3
BIDITEM 1 100 10000
BUY DRINK 4 2
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
AWARD PERSON 18
AWARD PERSON 16
AWARD PERSON 200
TOTAL REVENUE

Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab
Need help with my C-Project... Objective To learn how to write functions given specifications To learn how to the use pass by value and pass by reference variab

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site