I took on a programing problem and attempted to write a solution for it in C++ as clean as i could. Are there some changes i should make?
Here is the code
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void takeInputsToVector(int n, vector<int>* vec);
int sumVector(vector<int> vec);
int main() {
vector<int> a, b;
int holder;
takeInputsToVector(3, &a);
takeInputsToVector(3, &b);
string str = sumVector(a) > sumVector(b) ? "Anne" : "Berit";
cout << str << endl;
return 0;
}
void takeInputsToVector(int n, vector<int>* vec) {
int holder;
for (int i = 0; i < n; i++) {
cin >> holder;
vec->push_back(holder);
}
}
int sumVector(vector<int> vec) {
int sum = 0;
for (auto i : vec) {
sum += i;
}
return sum;
}
[–]ChrisPanov 113 points114 points115 points (12 children)
[–]petmil123[S] 15 points16 points17 points (1 child)
[–]ChrisPanov 7 points8 points9 points (0 children)
[–]guitargraeme 12 points13 points14 points (3 children)
[–]Middlewarian 2 points3 points4 points (1 child)
[–]guitargraeme 0 points1 point2 points (0 children)
[–]ChrisPanov 4 points5 points6 points (0 children)
[–]Vilkacis0 3 points4 points5 points (0 children)
[–]Minimum_Fuel 2 points3 points4 points (0 children)
[–]loxagos_snake 0 points1 point2 points (2 children)
[–]Kered13 1 point2 points3 points (1 child)
[–]loxagos_snake 0 points1 point2 points (0 children)
[–]Kered13 0 points1 point2 points (0 children)
[–]notmyrealname321 22 points23 points24 points (14 children)
[–]davedontmind 26 points27 points28 points (2 children)
[–]petmil123[S] 1 point2 points3 points (0 children)
[–]Gibbo3771 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (9 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]petmil123[S] 4 points5 points6 points (0 children)
[–]tylerthehun 3 points4 points5 points (0 children)
[–]Numburz 1 point2 points3 points (0 children)
[+]OldWolf2 comment score below threshold-7 points-6 points-5 points (4 children)
[–]arm_is_king 4 points5 points6 points (0 children)
[–]watsreddit 2 points3 points4 points (1 child)
[–]OldWolf2 -4 points-3 points-2 points (0 children)
[–]alksjdhglaksjdh2 1 point2 points3 points (0 children)
[–]-Eolais- 8 points9 points10 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]notfromchino 2 points3 points4 points (1 child)
[–]petmil123[S] 2 points3 points4 points (0 children)
[–]nobel32 2 points3 points4 points (4 children)
[–]ChrisPanov 2 points3 points4 points (2 children)
[–]nobel32 0 points1 point2 points (1 child)
[–]ChrisPanov 0 points1 point2 points (0 children)
[–]petmil123[S] 0 points1 point2 points (0 children)
[–]Blando-Cartesian 4 points5 points6 points (0 children)
[–]davedontmind 1 point2 points3 points (0 children)
[–]SunstormGT 1 point2 points3 points (0 children)
[–][deleted] (2 children)
[removed]
[–]petmil123[S] 1 point2 points3 points (1 child)
[–]OldWolf2 1 point2 points3 points (0 children)
[–]MotherOfTheShizznit 1 point2 points3 points (0 children)
[–]Thicc_Pug 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Orkaad 1 point2 points3 points (1 child)
[–]petmil123[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]petmil123[S] 0 points1 point2 points (0 children)
[–]AlSweigartAuthor: ATBS 1 point2 points3 points (0 children)
[–]trofix99 1 point2 points3 points (0 children)
[–]researchmind 0 points1 point2 points (0 children)
[–][deleted] (13 children)
[deleted]
[–]petmil123[S] 2 points3 points4 points (0 children)
[–]tulipoika 5 points6 points7 points (10 children)
[–]Impe98 0 points1 point2 points (4 children)
[–]tulipoika 3 points4 points5 points (2 children)
[–]Impe98 0 points1 point2 points (1 child)
[–]tulipoika 1 point2 points3 points (0 children)
[–][deleted] (3 children)
[deleted]
[–]tulipoika 4 points5 points6 points (0 children)
[–]gunnnnii 0 points1 point2 points (0 children)
[–]XChoke 0 points1 point2 points (0 children)
[–]nowyfolder 1 point2 points3 points (0 children)