Using Loop Statements Only..Help!

what is wrong with these???solving for a minimum and maximum

#include <iostream>
using namespace std;


int main () {

int a,b;

cout<<"how many nos. you want to input? ";
cin>>a;
int c[a];
int max = c[0];
int min = c[0];
for(int x=1;x<=a;x++) {

cout<<"input "<<x<<" ";
cin>>c[x];

for(int y = 0;y<a;y++) {
if(c[y]< min)
min = c[y];
if(c[y]> max)
max = c[y];
}
}
cout<<"max = "<<max<<endl;
cout<<"min = "<<min<<endl;
}
Last edited on
can you solve these for me??

Ummm, lol, of course not! This sin't the homework cheaters forum! Try to solv eit yourself, when you get REALLY stuck, post use your code, and we'll help you fix it! WE DO NOT SOLVE HOMEWORK FOR YOU!
:(
Last edited on
Hi,

Everything you need is there (plus your brain):

http://www.cplusplus.com/doc/tutorial/operators/
http://www.cplusplus.com/doc/tutorial/arrays/
http://www.cplusplus.com/doc/tutorial/control/

it won't take you a lot of time and it will help you more than you think.

Good luck
You should'nt edit your posts like that, it's more difficult to understand..

If you are looking for just the min and max, you don't need to imbricate two loops. One loop is enough to get the user values and compare them with the actual min and max.
In your case you ask the values and compare them with all the values of the array(initialised or not, you should init your array if you want to use one). Just store the actual min and max and compare each new input with them.
I have 3 words for you: std::min_element and std::max_element!
Topic archived. No new replies allowed.