| | |
max and min
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2006
Posts: 22
Reputation:
Solved Threads: 1
hi, i need help with how to find the max number and min number from an array. there are 31 numbers, i know that i am suppose to use a for loop to do this and this is what i got so far
array is inputed by user
this is where im stuck, i don't know what to do next. i need to find the max and min so now i just need to find a way to swap the order of the array so later on i can just cout the first and last element of the array to show the max and min.
array is inputed by user
C++ Syntax (Toggle Plain Text)
#include <iostream.h> int main () { int temp[31]; for(int i=0;i<31;i++) { cout<<"ENTER THE TEMPERATURE FOR THE MONTH OF DECEMBER"<<endl; cin>>temp[i]; } for(i=0;i<31;i++) { if(temp[i]>temp[i+1])
What I would do is this instead of the "read" loop:
Do you see where I'm going with this?
C++ Syntax (Toggle Plain Text)
int tmax, tmin; tmax=temp[0]; tmin=temp[0]; for(int i=0; i<31; i++){ if(temp[i]>tmax){ tmax=temp[i]; } if(temp[i]<tmin){ tmin=temp[i]; } } cout<<"The maximum temperature is "<<tmax<<".\n"; cout<<"The minimum temperature is "<<tmin<<".\n";
Last edited by venomlash; Jan 7th, 2008 at 9:41 pm. Reason: Clarify
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
Writing an array-sorting algorithm has been the bane of intro-C++ courses since the language was invented, I think. Being a hobbyist, I try to avoid having to sort. If you just need the max and min, what I posted should work fine. If not, ask someone more experienced.
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
![]() |
Similar Threads
- Need some help with min/max in arrays (C++)
- Max and Min values from a group of numbers (C++)
- How can i find out the Max and Min value from a Vector? (C++)
- array max min (C++)
- beginners program; can't get min value (C++)
Other Threads in the C++ Forum
- Previous Thread: Port Scanner in C++
- Next Thread: 'system': identifier not found
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates text tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





