Hi so the goal of this program is to find the largest element calling from maxv but for some reason it keeps giving me the last value. I'd appreciate any help, thanks!
int maxv (vector<int>v)
{
int max = v[0];
for(int i = 0; i < v.size(); ++i){
if (max < v[i])
max = v[i];
}
return max;
}
int main()
{
int input;
vector <int> v;
//Input values
cout << "Input numbers:\n";
//convert string to vector
while (cin >> input);
{
v.push_back(input);
}
//Read out max value
cout << "\nMaximum value was v["<<v.size() "] = "<< maxv (v);
#include <string>
#include <conio.h>
#include <iostream>
#include <vector>
usingnamespace std;
int maxv (vector<int>v)
{
int max = v[0];
for(int i = 0; i < v.size(); ++i)
{
if (max < v[i])
max = v[i];
}
return max;
}
int main()
{
int input;
vector <int> v;
int i=0;
//Input values
cout << "Input numbers:\n";
//convert string to vector
while (i<5)
{
cin >> input;
v.push_back(input);
i++;
}
//Read out max value
cout << "\nMaximum value was v"<<endl;
cout<< maxv(v);
getch();
return 0;
}
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <algorithm>
usingnamespace std;
int main()
{
string temp = "";
vector<double> numVec;
//get a line from user
cout << "Please enter a list of numbers: " << flush;
getline(cin, temp);
stringstream ss(temp);
double tempDouble = 0;
//convert userinput to double
while (ss >> tempDouble)
{
numVec.push_back(tempDouble);
}
//returns an iterater to the max number
auto max = max_element(numVec.begin(), numVec.end());
cout << "The maximum number is " << *max << endl;
cin.ignore();
return 0;
}