Thread: Array (range lowest to highest)

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    6

    Array (range lowest to highest)

    In this program I have to give the range from lowest to highest of scores for each quiz.


    I need some assistance with my if-statment. Im not sure what condition put inside the if-statment. Can someone here help me set it up?


    Thanks for any helpful replies
    Last edited by flutegirl516; 02-18-2010 at 04:30 PM.

  2. #2
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    I think the simplest way to do this would be like this:

    for each quiz:
    iterate through all grades:
    use two variables called highest and lowest or something, and basically for each value:
    if value < lowest then lowest = value
    if value > highest then highest = value
    print out the quiz number and range

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    6
    Thanks for replying. Okay I'll give it try

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    6
    This is what I implemented. But the output is weird.
    for( col = 0; col < QUIZZES; col++ ){
    for( row = 0; row < STUDENTS; row++ ){
    if( value > high ){
    high = value;
    }
    if( value < low ){
    low = value
    }
    // Should I put I put the high = -1 and low = 100?
    }

    printf("Quiz %i: %i - %i\n", col, low, high); < - Maybe my printf is wrong ??
    }
    Here is the output:
    Quiz 1: 0 - 0
    Quiz 2: 0 - 0
    etc...

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    6
    Any suggestions?

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > low = -1, high = 100; // <- intialized the high and low
    Then later
    > // Should I put I put the high = -1 and low = 100?

    Yes, do the second thing in the place of the first thing.
    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.

  8. #8
    Registered User
    Join Date
    Feb 2010
    Posts
    6
    Yea I saw that mistake now it displays as : 101 - -1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extracting lowest and highest score from array
    By sjalesho in forum C Programming
    Replies: 6
    Last Post: 03-01-2011, 06:24 PM
  2. warning: excess elements in array initializer
    By redruby147 in forum C Programming
    Replies: 6
    Last Post: 09-30-2009, 06:08 AM
  3. Few arguments
    By caroundw5h in forum C Programming
    Replies: 8
    Last Post: 07-22-2004, 11:08 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM