Array (range lowest to highest)

This is a discussion on Array (range lowest to highest) within the C Programming forums, part of the General Programming Boards category; In this program I have to give the range from lowest to highest of scores for each quiz. I need ...

  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 03:30 PM.

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    944
    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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648

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

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 05: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21