i want to put the input for n / anzahl and the output of the minimum and maximum temperature in the main function while having the calculation in the void function. i think my mistake is by calling the wrong reference but i can't see it. can someone help me see my mistake?
i got this so far. this code is everything in the main function, it works perfectly but i have problems with the realization of putting the output in the main function
#include <iostream>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int n,i;
int groesst, kleinst;
int rand(void);
cout << "Geben Sie Anzahl der Temperaturwerte an: "; //put in the amount of temperatures
cin >> n;
n=n+1; //so non programmers arent confused
vector<int> temp(n);
cout << "31 zufaellige Temperaturen:\n" << endl;
groesst = temp[0];
kleinst = temp[0];
for (i=1;i<n;i++)
{
temp[i]=rand()%20-4;//random temperature between -4 and 15
cout << temp[i] << " Grad Celsius"<< endl;
if (temp[i]>groesst) //
{
groesst = temp[i]; //
}
if (temp[i]<kleinst)
{
kleinst = temp [i];
}
}
cout << kleinst; //minimum temperature
cout << "\n";
cout << groesst; //maximum temperature
return 0;
}
this is my attempt:
#include <iostream>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
void minmaxim(vector<int>& temp, int& n, int& kleinst, int& groesst)
{
int i;
int rand(void);
temp[n];
groesst = temp[0];
kleinst = temp[0];
for (i=1;i<n;i++)
{
temp[i]=rand()%20-4;
if (temp[i]>groesst)
groesst = temp[i];
}
if (temp[i]<kleinst)
{
kleinst = temp [i];
}
return;
}
int main ()
{
vector<int> temps;
int anzahl, minimum,maximum;
cout << "Geben Sie die Anzahl der Temperaturwerte ein: "; //type in the amounts of temperatures
cin >> anzahl;
minmaxim(temps, anzahl, minimum, maximum); //calling the function
cout << " " << anzahl;
cout << " " << minimum <<endl;
cout << " " << maximum <<endl;
return 0;
}