So I'm working on a program which finds the highest number of numbers in a vector. It may be lengthy, but that's just because its easier to put different functionality in different loops and places, I've learned. Trying to make one loop do three different things is verrrryy difficult.
I don't know why when I run this, it gets to the loop which finds the ties or highest number of those, and skips the entire loop!
#include<vector>
#include<time.h>
#include<iostream>
usingnamespace std;
void stats (vector<int> MyVector ) { //CORRECT SYNTAX. No Dual Parantheses, in passing or recieving.
vector <int> MyTallyVector (10);
for (unsignedint counter = 0; counter < MyVector.size(); counter += 1 ) {
int VectorContainer = MyVector.at(counter);
switch (VectorContainer) {
case 2:
MyTallyVector.at(0) += 1;
cout << "Added one to 2 Tally\n";
break;
case 3:
MyTallyVector.at(1) += 1;
cout << "Added one to 3 Tally\n";
break;
case 4:
MyTallyVector.at(2) += 1;
cout << "Added one to 4 Tally\n";
break;
case 5:
MyTallyVector.at(3) += 1;
cout << "Added one to 5 Tally\n";
break;
case 6:
MyTallyVector.at(4) += 1;
cout << "Added one to 6 Tally\n";
break;
case 7:
MyTallyVector.at(5) += 1;
cout << "Added one to 7 Tally\n";
break;
case 8:
MyTallyVector.at(6) += 1;
cout << "Added one to 8 Tally\n";
break;
case 9:
MyTallyVector.at(7) += 1;
cout << "Added one to 9 Tally\n";
break;
case 10:
MyTallyVector.at(8) += 1;
cout << "Added one to 10 Tally\n";
break;
case 11:
MyTallyVector.at(9) += 1;
cout << "Added one to 11 Tally\n";
break;
case 12:
MyTallyVector.at(10) += 1;
cout << "Added one to 12 Tally\n";
break;
default:
//rather useless holdover from implementing this switch case.
cout << "The VectorContainer did not match any range value.\n";
break;
}
}
//This loop will simply print the tallies.
for (unsignedint c = 0; c < MyTallyVector.size(); c++ ) {
cout << "There were: " << MyTallyVector.at(c) << " " << c + 2 << "'s \n";
// I want this to tally the votes by replacing each element which is high, with the next highest one. If there is a tie, then the tied tallies will be stored.
staticbool TieBool = false;
staticint MaxSum = 0;
int StoreThisOne = 0;
int StoreThisTwo = 0;
for (unsignedint count = 0; count < MyTallyVector.size(); count += 1) {
if (MyTallyVector.at(0) == 0 ) { }
elseif (MyTallyVector.at(count) > MaxSum) {
MaxSum = MyTallyVector.at(count);
TieBool = false;
StoreThisOne = count + 2;
}
elseif (MyTallyVector.at(count) == MaxSum ) {
TieBool = true;
StoreThisTwo = count + 2;
}
}
if (TieBool == true) {
cout << "Two ties were found: " << StoreThisOne << " " << StoreThisTwo << "\n";
}
else { cout << "The highest number of votes was: " << StoreThisOne << " \n";
}
}
int main () {
int pause = 0;
vector <int> MyVector (6);
//These should really be alphabetical characters, but its easier to just use numbers right now.
MyVector.at(0) = 3;
MyVector.at(1) = 3;
MyVector.at(2) = 5;
MyVector.at(3) = 9;
MyVector.at(4) = 9;
MyVector.at(5) = 9;
stats (MyVector );
cin >> pause;
return 0;
}