Thread: C Programming: Find maximum and minimun.

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    1

    C Programming: Find maximum and minimun.

    Hi, I am a in a beginner c programming class and need help with a project. I need to find the minimum and the maximum for the following.


    Candidate Results
    Id J1 J2 J3 totalScore
    4 2 0 3 5
    3 3 4 10 17
    7 9 1 0 10
    1 5 0 7 12
    13 6 10 5 21
    2 6 5 1 12
    6 0 8 4 12
    5 7 9 9 25
    8 0 2 5 7
    9 7 7 6 20
    10 1 6 2 9
    12 4 9 0 13
    11 0 3 6 9
    13 Total Candidates
    Average total score is 13.0







    This is what I have so far.

    Code:
    #include<stdio.h>
    main()
    {
          FILE *inCanResults, *outCanResults;
          inCanResults = fopen("data2a.txt", "r");
          outCanResults = fopen("out2a.txt", "w");
          int ctr, idNum, j1, j2, j3, total, count, totalScore, e;
          float avg;       
          e=fscanf(inCanResults,"%d %d %d %d", &idNum, &j1, &j2, &j3); 
          printf("      Candidate Results\n");
          printf("Id    J1    J2    J3    totalScore\n");
          fprintf(outCanResults,"      Candidate Results\n");
          fprintf(outCanResults,"Id    J1    J2    J3    totalScore\n");
          ctr = 0;
          total = 0;
          
          while (e==4)
          {
             totalScore = j1 + j2 + j3;
             printf("%d %5d %5d %5d %9d\n", idNum, j1, j2, j3, totalScore);
             fprintf(outCanResults,"%d %5d %5d %5d %9d\n", 
                                       idNum, j1, j2, j3, totalScore);
             ctr = ctr + 1;
             count = count + 1;
             total = totalScore + total;
             e=fscanf(inCanResults,"%d %d %d %d", &idNum, &j1, &j2, &j3);
          }
          avg = total / ctr;
          printf("       %d Total Candidates\n", count);
          fprintf(outCanResults,"       %d Total Candidates\n", count);
          printf("       Average total score is %.1f\n", avg);
          fprintf(outCanResults,"       Average total score is %.1f\n", avg);
          printf("Top candidate is number %d with score of %d\n", 
                      idNum, totalScore);
          fprintf(outCanResults,"Top candidate is number %d with score of %d\n", 
                      idNum, totalScore);
          printf("Bottom is number %d with score of %d\n", idNum, totalScore);
          fprintf(outCanResults,"Bottom is number %d with score of %d/n", 
                      idNum, totalScore);
          fclose(inCanResults);
          fclose(outCanResults);
          system("pause");   
          }
    The book we are using doesn't explain this very well so I would appreciate some help. Thank you!!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Since you aren't storing them all in memory as you read them, you will need to include checks for the values you have just read, and test whether or not they are bigger or smaller than what you already have.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find Maximum!
    By alireza beygi in forum C Programming
    Replies: 2
    Last Post: 01-06-2012, 05:41 PM
  2. find the maximum width & length of a box using for loops?
    By bac3bac0mm in forum C Programming
    Replies: 1
    Last Post: 03-17-2011, 10:23 PM
  3. Best way to find maximum number
    By mutombo in forum C Programming
    Replies: 3
    Last Post: 02-27-2009, 04:36 AM
  4. Where can I find C programming challenges
    By Trafalgar Law in forum Tech Board
    Replies: 6
    Last Post: 09-22-2008, 07:44 PM
  5. Find maximum number (while loop)
    By katherene in forum C++ Programming
    Replies: 1
    Last Post: 10-16-2006, 05:44 PM