#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
// To Do: Finish this function
void yourFunction(int N, vector<float>&vec, float &m, float &n){
sort(vec.begin(), vec.end());
n=vec[0];
m=vec[N];
}
int main()
{
int N;
float m,n;
cout << "Please enter the length of array." << endl;
cin >> N;
float *p = (float*) malloc(sizeof(float)*N);
cout << "Please enter the numbers in your array.";
for(int i=0;i<N;i++)
cin >> *(p+i);
vector<float>vec(p[0],p[N-1]);
yourFunction(N,vec,m,n);
cout << "The largest number in your array is " << m << endl;
cout << "The smallest number in your array is " << n << endl;
return 0;
}
So this is a C++ program that is meant to identify the largest and smallest number in a user-inputted array. Code::Blocks 16, C++0X standards.
In its current state, however, when I input 1 2 3 4 5
for the array, the program's output is as following:
https://i.stack.imgur.com/phktl.png
What is the problem here? I am an amateur coder and am probably making some dumb mistakes I didn't notice. :P