I have this code which gets a string from the user, and it will find the digits and put them in a vector. Then it will find the highest number in the vector.
Question: How should I edit it so it would find if its even or odd?
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
using namespace std;
int main() {
string str;
getline(cin, str);
vector<int> vec;
for(int i = 0; i < str.length(); i++){
if(isdigit(str[i])){
vec.push_back(str[i]);
}
}
int max = *max_element(vec.begin(), vec.end());
if(max / 2 == 0){
cout << "is even";
} else {
cout << "is odd";
}
return 0;
}
i want an output such as this:
input:
Hgj326nm2tgh21salamcup
output:
is even
or
input:
eMok2404fggh5987fgf52fgf21
output:
is odd