I need help finding the coldest temperature using an array. I already found how to get the warmest temperature.
[code]
#include <iostream>
#include <fstream>
using namespace std;
int Warmest(const int A[], int n)
{
int warm=-1;
for(int i=0;i<n;i++)
if(A[i]>warm) warm = A[i];
return warm;
}
int ReadData(int A[], int n)
{
ifstream file;
file.open("temp.dat");
int k=0;
if(file)
{
while(file)//while last read was successful
{
if(k>=n) break;
file>>A[k];
cout<<A[k]<<endl;
k++;
}
}
file.close();
return k;
}
int main() {
int A[31];
ReadData(A,31);
int n = ReadData(A,31);
int hotest=Warmest(A,n);
cout<<"Warmest days's temp:"<<hotest<<endl;
return 0;
}
[code]
int Coldest(const int A[], int n)
{
int cold = A[0]; //consider doing this on warm too. what if all the data were from antartica?
for(int i=1; i<n;i++)
if(A[i] < cold) cold = A[i];
return cold;
}