473,480 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

49 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.     int numbers; //holds a number of integers
  9.     int numMax; //Holds max value
  10.     int numMin; //holds min value
  11.  
  12.     cout << "Please enter a series of integers,\n";
  13.     cout << "when finished input -99, then press ENTER." << endl << endl;
  14.     cin >> numbers;
  15.  
  16.  
  17.     while (numbers != -99)
  18.     {
  19.         numMax
  20.  
  21.         cout << "Greatest number in the series is: " << numMax << endl;
  22.         cout << "Least number in the series is: " << numMin << endl;
  23.         cin >> numbers
  24.     }
  25.  
  26.  
  27. return 0;
  28.  
  29. }
  30.  
Apr 17 '07 #1
5 6776
RedSon
5,000 Recognized Expert Expert
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
Apr 17 '07 #2
RedSon
5,000 Recognized Expert Expert
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.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.     int numbers; //holds a number of integers
  9.     int numMax; //Holds max value
  10.     int numMin; //holds min value
  11.  
  12.     cout << "Please enter a series of integers,\n";
  13.     cout << "when finished input -99, then press ENTER." << endl << endl;
  14.     cin >> numbers;
  15.  
  16.  
  17.     while (numbers != -99)
  18.     {
  19.         numMax
  20.  
  21.         cout << "Greatest number in the series is: " << numMax << endl;
  22.         cout << "Least number in the series is: " << numMin << endl;
  23.         cin >> numbers
  24.     }
  25.  
  26.  
  27. return 0;
  28.  
  29. }
  30.  
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
Expand|Select|Wrap|Line Numbers
  1. cout << "Please enter a series of integers,\n";
  2. cout << "when finished input -99, then press ENTER." << endl << endl;
  3. cin >> numbers;
  4.  
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!
Apr 17 '07 #3
Ganon11
3,652 Recognized Expert Specialist
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?
Apr 17 '07 #4
RedSon
5,000 Recognized Expert Expert
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!
Apr 17 '07 #5
zizz
1 New Member
Were you able to finish your program after all?
Oct 17 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2093
by: Josh | last post by:
Howdy i am newb somewhat to programing and i was just for fun trying to compile a program that asks the user for an odd int less than 22 and then returns this ***************** ******* *********...
5
1537
by: Nikola | last post by:
I need to write a program that generates 5 random numbers and puts them into a linked list. (Print the list) From that list it forms another list in a way if the arrangement of elements in the...
9
11505
by: kwindham | last post by:
This program doesn't seem like it should be too hard, but I cannot figure it out. Here is the assignment: Password Verifier - Write a program to verify passwords, satisfying the following...
5
1797
by: ComicCaper | last post by:
Hi all, I use a quiz program that accepts a text file for questions and answers in this format: Question Answer1 <----is the correct answer. Quiz randomizes answers. Answer2 Answer3...
7
7104
by: steve marchant | last post by:
trying to learn VB6. Simple counting loop which counts to 8 in 1 sec intervals, then starts from 1 again and repeats. Have two Command buttons on the form. Cmd1 starts the counting, and I need to...
1
2007
aprilmae36
by: aprilmae36 | last post by:
Nice day to all... I'm new in java programming and I'm having some problem with this program. The problem is this: Write a program that will read an unspecified number of non-zero integers and...
2
4328
by: mika_ella258 | last post by:
the output should be like this Loop Program -------------------- enter 1st integer: enter 2nd integer: enter 3rd integer: enter 4th integer: enter 5th integer:
4
1216
by: charmeda103 | last post by:
i working on a program in c++ and my program is to read data from a file. I using a while loop. the while loop is not reading the dates of each line. mm/dd/yyyy everything in the file is reading...
0
7039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7037
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6735
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5326
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1296
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
176
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.