Thread: Help with Silent Auction Program?

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

    Help with Silent Auction Program?

    Hi, I m having a lot of trouble with this program I have to write in C. I have to read input from a file with a user inputted name for a silent auction.
    The file contains data like this
    5
    4
    100 500 250 300
    1
    700
    3
    300 150 175
    2
    920 680
    8
    20 10 15 25 50 30 19 23

    The first number is the amount of items for sale, The numbers <10 are the number of bids per item. The numbers under are the bid. So for
    1
    700 It should say "Auction 2 was sold at $700.00" Since it s the second one with numbers under it. Please help

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    In pseudo code

    Code:
    read the number of auctions
    for ( i = 0 ; i < number of auctions ; i++ ) {
      read the number of bids
      initialise max bid to 0
      for ( j = 0 ; j < number of bids ; j++ ) {
        read a bid
        compare with max bid, and adjust accordingly
      }
      output the max bid
    }
    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.

  3. #3
    Registered User
    Join Date
    Oct 2016
    Posts
    2
    So far I have this
    Code:
    # include <stdio.h># include <stdlib.h>
    # include <time.h>
    
    
    
    
    int main () {
    
    
        FILE * ifp;
        ifp = fopen("auction.txt", "r");
    
    
    
    
        float winning_bid[5];
        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 (j=i; j<num_bids; j++) {
    
    
    
    
                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);
            }
    
    
    
    
            //keep a running sum of total made from auctions
    
    
    
    
    
    
    
    
    
    
    
    
        }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Silent Auction Program
    By Bense_Mamba in forum C Programming
    Replies: 2
    Last Post: 10-11-2016, 01:04 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-Strike
    By Breach23 in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 10-28-2001, 01:05 PM

Tags for this Thread