#include <iostream>
using namespace std;
double max (double array[], int size);
int main ()
{
double large[8],x=8, maximum;
int num;
cout << "Enter eight numbers, one at a time, and the program will return the largest number. \n";
cout << "Enter first number : ";
cin >> large[8];
for (int i=1; i<x; i++)
{
cout << "Enter another number :";
cin >> num;
maximum = max(large,num);
}
cout << "\nThe largest number is " << maximum;
return 0;
}
double max (double array[], int size)
{
double x;
x = array[0];
int y;
if (x>y)
return x;
else
return y;
}
#include <iostream>
usingnamespace std;
double max(double array[], int size);
int main() {
double large[8], x = 8, maximum;
int num;
cout << "Enter eight numbers, one at a time, and the program will return ""the largest number. \n";
cout << "Enter first number : ";
cin >> large[8]; //out of bounds
for(int i = 1; i < x; i++) {
cout << "Enter another number :";
cin >> num; //so we read in `num', ¿what was the purpose of the array `large'?
maximum = max(large, num); //max(array = large, size = num) ¿`num' represents a size?
}
cout << "\nThe largest number is " << maximum;
return 0;
}
double max(double array[], int size) {
//size is unused.
double x;
x = array[0]; //you asked for an array but just use one element (which comes uninitialised from main)
int y; //uninitialised
if(x > y) //using an uninitialised variable: undefined behaviour
return x;
elsereturn y; //returning an uninitialised variable
}