I'm a beginner programmer...I'm trying to write a piece of code which does these actions in order:
- Asks the user how many numbers he/she wants to enter
- gets the numbers from input and store them in the vector using the
.push_back
method - finding the max and min element using
*max_element(vector.begin(), vector.end()
and*min_element(vector.begin(), vector.end())
I've tried these methods and this is the error I get:
error: no match for 'operator<<' (operand types are 'std::vector<int>::iterator' {aka '__gnu_cxx::__normal_iterator<int*, std::vector<int> >'} and '<unresolved overloaded function type>')
And this is the piece of code I've written:
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int times{};
int input{};
cout << "How many numbers do you want to enter? ";
cin >> times;
vector <int> Data(times);
cout << "Enter the numbers: ";
for(int i{1}; i<=times; i++){
cin >> input;
Data.push_back(input);
}
cout << "Max = " << *max_element(Data.begin(), Data.end() << endl;
cout << "Min = " << *min_element(Data.begin(), Data.end()) << endl;
return 0;
}
I don't know what I've done wrong here...If anyone can help I would highly appreciate it...
Aucun commentaire:
Enregistrer un commentaire