Program background:
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.
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 followed by a positive real value to two decimal places (at most) representing the minimum bid increment, in dollars. The first value is guaranteed to be 1000 or less and the second will be in between 1 and 50, inclusive.
The third line of the file will contain all the prices of the auction items, in dollars, separated by spaces, in order. Thus, the first price is the price of item 0, the next price is the price of item 1, and so on. These values will be real numbers represented to up to 2 decimal places.
The fourth line of the file will contain the three following positive integers pertaining to the raffle: the number of raffle tickets available, the cost of a raffle ticket in dollars, and the number of raffle prizes. (It's strange to have raffle tickets that don't cost a whole number of dollars.)
The fifth line of the file will contain each of the values of the raffle items, in dollars, separated by spaces, in order. Thus, the first price is the price if item 0, the next price is the price of item 1, and so on. These values will be real numbers with upto 2 decimal places.
The sixth line of the file will contain ten positive integers representing the number of each of the drinks 0 through 9, in order, that are in stock.
The seventh line of the file will contain ten positive real numbers with upto 2 decimal places representing the price of each of the drinks 0 through 9, in order.
The eighth line of the file will contain a single positive integer, numEvents, representing the number of events that occur at the charity ball. 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.
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.
This is what I have so far and I cannot figure out why it wont calculate the total revenue. I am not completely sure if it is even accessing the if statement in main.
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1000 //Function for the tickets bought. int buy_tickets(int x); int num_presale,cost_presale, cost_at_door, num, total_revenue=0; int guests[N] = {0}; char buyticket[]; int main(){ FILE * ifp =fopen("auction01.txt","r"); // Used to find the string Buy Ticket in the file auction01.txt char command_ticket[10] = "BUY TICKET"; char command[20]; //Call the numbers from the file auction01.txt fscanf(ifp,"%d", &cost_presale); fscanf(ifp,"%d", &cost_at_door); fscanf(ifp,"%d", &num_presale); fscanf(ifp,"%s", command); // Using an if statement to find the string "Buy Ticket" if ( strcmp(command ,command_ticket) == 0) { fscanf(ifp, "%s", command_ticket); fscanf(ifp ,"%d", &num); // Calling the function buy_ticket int buy_tickets(num); } // Here for reference to make sure the file is being read printf("Presale cost: %d\nCost at door: %d\nNumber of presale: %d\n\n", cost_presale, cost_at_door, num_presale); fclose(ifp); // Print the total revenue in the file from the presold tickets and cost_at_door. printf("The total revenue is $%.2lf\n", total_revenue); return 0; } // function to calculate the the number of tickets int buy_tickets(int x){ int i, first_ticket, last_ticket, total; static int guest_count = 0; for (i=0 ; i<x ; i++){ if (num_presale != 0 ){ total_revenue += cost_presale; num_presale--; } else{ total_revenue += cost_at_door; } guests[guest_count] = guest_count; if (i == 0) first_ticket = guest_count; if (i == x-1) last_ticket = guest_count; } total = first_ticket - last_ticket; printf("The number of sold tickets are %d - %d =%d", first_ticket, last_ticket, total ); return num; }