Thread: Silent Auction Program

  1. #1
    Registered User
    Join Date
    Oct 2016
    Posts
    2

    Post Silent Auction Program

    Programmers for a Better Tomorrow is hosting a silent auction to benefit one of their main charities. Participants in a silent auction write down which item they are bidding for and how much they are willing to bid.

    This program will read from a file that contains a list of bids on a number of auctions. The program must determine the amount that each item will be sold for. This will be the highest amount that someone is willing to bid on that item.

    When the final bid amount for each item has been determined, print this information to the screen.

    Finally, calculate the total amount of money made for the auction (the sum of the final bids of each item) and print this information to the screen.

    Arrays are not required (except for the name of the input file), but may simplify your solution.

    Input Specification The file name will be a string less than 30 characters in length. There will be no other input from the user.

    Input File Specification The first line of the file will contain a single positive integer, n (n <= 10), representing the number of items up for auction. Information about each auction follows.

    The first line of each auction will contain a single positive integer, k, representing the number of bids on that item. Following this value there will be k integers, in any order, that represent the individual bids on that item in dollars.

    Output Specification Output to the screen. For each auction, print the following:

    2
    Auction #A was sold for $X.XX!

    where A is the number of the auction and X is the highest bid for that auction.

    At the end of the program, print the total amount of money the auction raised:

    The silent auction raised $Y.YY for charity!

    Sample Run Below is a sample output of running the program. Note that this sample is NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above.

    In the sample run below, for clarity and ease of reading, the user input is given in italics while the program output is in bold. (Note: When you actually run your program no bold or italics should appear at all. These are simply used in this description for clarity’s sake.)

    Sample Input (input.txt) 5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23

    Sample Output Please enter the name of the weather data file for Dragon Island. input.txt

    Auction 1 was sold for $500.00! Auction 2 was sold for $700.00! Auction 3 was sold for $300.00! Auction 4 was sold for $920.00! Auction 5 was sold for $50.00!

    The silent auction raised $2470.00 for charity!

  2. #2
    Registered User
    Join Date
    Oct 2016
    Posts
    2
    Code:
    # include <stdio.h># include <stdlib.h>
    # include <time.h>
    
    
    
    
    int main () {
    
    
    
    
        FILE * ifp;
    
    
    
    
        ifp = fopen("bids.txt", "r");
    
    
    
    
        float winning_bid[10000];
        int num_auctions, num_bids, max_bid=0, current_bid, next_bid, i, j,sum=0;
    
    
    
    
        fscanf(ifp, "%d", &num_auctions);
    
    
    
    
         //Loop set up based on the number of auctions
        for (i=0; i<num_auctions; i++) {
    
    
    
    
            fscanf(ifp, "%d", &num_bids);
    
    
    
    
            for (i=0; i<num_bids; i++) {
    
    
    
    
                fscanf(ifp, "%d", &current_bid);
    
    
    
    
                        if (current_bid > max_bid )
                                max_bid = current_bid;
    
    
    
    
    
    
    
    
        printf("Auction %d sold for $%d.\n", i+1, max_bid);
            }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well it looks good so far, what did you want to know?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Silent Hill??
    By swgh in forum Game Programming
    Replies: 8
    Last Post: 06-01-2005, 07:23 AM
  2. Interesting eBay auction.
    By adrianxw in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 11-03-2003, 01:36 AM
  3. auction
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 12-11-2002, 10:12 AM
  4. Silent Wolf
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 01:11 PM

Tags for this Thread