Display the largest and smallest valleys of an array?

Hi there,

I am working on a c++ assignment and I need to display the smallest and largest values of an array called from a .txt file...but I don't know how to display them...any guidance?

This is what I have so far::

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>

using namespace std;

int main(){
string n;
int array[36];

ifstream infile;
infile.open("nums.txt", ifstream::in);



for(int i = 0; i < 36; i++)

{
infile >> n;

array[i] = atoi(n.c_str());

}
infile.close();

for (int i=0; i < 36; i++)
{
cout << array[i] << " ";
}
cout << "\n\n";



return 0;
}




and the .txt file is:

12 43 11 10 9 54 36 75 96 83 23 35 67 35 47 58 69 13
45 67 89 78 66 44 1 55 59 81 18 0 42 199 4 100 46 76


any guidance? I'm just lost.

min=0,max=0;

if(array[i]<min)
{
min=array[i];
}


if(array[i]>max)
{
max=array[i];
}

u can use any loop.
Thank you so much, however that doesn't seem to compile..it has an issue with re-calling array[i]...

here is the code:

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>

using namespace std;

int main(){
string n;
int array[36];

ifstream infile;
infile.open("nums.txt", ifstream::in);



for(int i = 0; i < 36; i++)

{
infile >> n;

array[i] = atoi(n.c_str());

}
infile.close();

for (int i=0; i < 36; i++)
{
cout << array[i] << " ";
}
cout << "\n\n";

int min = 0;
int max = 0;

if(array[i]<min)
{
min = array[i];
}

cout << "The smallest value is: " << min << endl;
cout << "The largest value is: " << max << endl;



return 0;
}


and the error message is:

assignment8.cpp: In function ‘int main()’:
assignment8.cpp:36: error: name lookup of ‘i’ changed for ISO ‘for’ scoping
assignment8.cpp:36: note: (if you use ‘-fpermissive’ G++ will accept your code)

..any idea?
Topic archived. No new replies allowed.