Find maximum number (while loop)

This is a discussion on Find maximum number (while loop) within the C++ Programming forums, part of the General Programming Boards category; alright so you guys seemed like the people to ask. my teacher asked me to basically do this: take a ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    ohio
    Posts
    1

    Question

    alright so you guys seemed like the people to ask.

    my teacher asked me to basically do this:

    take a bunch of numbers and find the highest, i have to use a while loop to get all the numbers. I have no clue how that would look in code and my book is a piece of ........ so it doesn't help.

    the actual promt is : a teacher has a set of student grades and wants to know the highest grade in the class regardless of the number of students in the class. develope a program to accomplish this

    a pseudocode or agorethm is helpful

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Welcome to the forum, katherene

    (Next time, click New Thread to start a new topic.)

    It depends on how the grades are given to you. They will probably be given in an array, or from a disk file.

    The general idea is to initialize Max (and Min) to the first value.

    Assuming the grades are stored in an array, the first grade in the list is Grade[0].
    Code:
    Max = Grade[0];  // Initialize Max and Min before entering the loop.
    Min = Grade[0];  // Max and Min are the same until you check the next grade in the list
    Then you go into a loop and compare the next grade to the Max & Min, updating if necessary...
    Code:
    if( Grade[1] > Max)  // Update Max if needed
         {
         Max = Grade[1];
         }
    
    if( Grade[1] < Min)  // Update Min if needed
         {
         Min = Grade[1];
         }
    When you do this in your loop, the array index will be a variable. Something like this:
    Grade[i]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. trouble with creating a loop to read certain number of inputs
    By import tuner650 in forum C++ Programming
    Replies: 2
    Last Post: 03-20-2008, 07:28 PM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  4. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  5. Print Maximum number
    By rmathus in forum C Programming
    Replies: 3
    Last Post: 10-07-2003, 06:33 AM

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