C++ Max and Min Loop Program.....Help!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mturner64
    New Member
    • Feb 2007
    • 49

    C++ Max and Min Loop Program.....Help!

    Good day. I am working on a program that will allow a user to enter an undefined series of numbers and enter -99 when finished. The program should output the Greatest and Least of the series entered. The instructor reccommends using a while loop and the loop is where I am getting lost. Any help is appreciated. Thanks... My code is below.
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main()
    {
    
    	int numbers; //holds a number of integers
    	int numMax; //Holds max value
    	int numMin; //holds min value
    
    	cout << "Please enter a series of integers,\n";
    	cout << "when finished input -99, then press ENTER." << endl << endl;
    	cin >> numbers;
    
    
    	while (numbers != -99)
    	{
    		numMax
    
    		cout << "Greatest number in the series is: " << numMax << endl;
    		cout << "Least number in the series is: " << numMin << endl;
    		cin >> numbers
    	}
    
    
    return 0;
    
    }
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

    Then when you are ready post a new question in this thread.

    MODERATOR

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      Originally posted by mturner64
      Good day. I am working on a program that will allow a user to enter an undefined series of numbers and enter -99 when finished. The program should output the Greatest and Least of the series entered. The instructor reccommends using a while loop and the loop is where I am getting lost. Any help is appreciated. Thanks... My code is below.
      Code:
      #include <iostream>
      #include <iomanip>
      using namespace std;
      
      int main()
      {
      
      	int numbers; //holds a number of integers
      	int numMax; //Holds max value
      	int numMin; //holds min value
      
      	cout << "Please enter a series of integers,\n";
      	cout << "when finished input -99, then press ENTER." << endl << endl;
      	cin >> numbers;
      
      
      	while (numbers != -99)
      	{
      		numMax
      
      		cout << "Greatest number in the series is: " << numMax << endl;
      		cout << "Least number in the series is: " << numMin << endl;
      		cin >> numbers
      	}
      
      
      return 0;
      
      }
      Ok now that my previous post response is out of the way. It looks like you have a good start to your program here. First off I see that you only get input once. You may want to put
      Code:
      cout << "Please enter a series of integers,\n";
      cout << "when finished input -99, then press ENTER." << endl << endl;
      cin >> numbers;
      in a loop too so that you can get more then one number. Another thing I dont see is how you are going to detect and store the highest number. You should take a minute to do a proper design for your application by attempting it first on a sheet of paper. Pretend you are the computer and write down the steps. Then work through the steps for an input of one number. Then of two numbers, then of three numbers. That will give you a good understanding of your problem. Then you will be ready to program!

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        Actually, RedSon, the OP has a second input statement: check the last line inside the while loop :) However, the OP has no cout << statements indicating that another number should be entered, and I agree with your advice on this matter.

        So far, you are getting the numbers properly; however, you aren't doing anything to check for a maximum or minimum. Do you know yet how you'll do this?

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          Originally posted by Ganon11
          Actually, RedSon, the OP has a second input statement: check the last line inside the while loop :) However, the OP has no cout << statements indicating that another number should be entered, and I agree with your advice on this matter.

          So far, you are getting the numbers properly; however, you aren't doing anything to check for a maximum or minimum. Do you know yet how you'll do this?
          Ahh good catch. I should be more careful when glancing at someone's code!

          Comment

          • zizz
            New Member
            • Oct 2008
            • 1

            #6
            Were you able to finish your program after all?

            Comment

            Working...