I'm trying to write a program that reads a sequence of chars for a voting problem. The input is as follow:
YNNAPYYNY
YAYAYAYA
PYPPNNYA
YNNAA
NYAAA
#
'#' indicates the end of input. Each line is considered one vote, and so each line will have its own output (vote). So I need to read each line determine its ouput depending on the characters (Y,N,A,P) and move on to the next line do the same and keep going until # is reached. My question is how would I write the function that reads the input?
#include <iostream>
#include <iostream>
#include <string>
#include <stdlib.h>
usingnamespace std;
int Yvote = 0;
int Nvote = 0;
int Pvote = 0;
int Avote = 0;
//get line function which takes in a set characcters from input and sets them as string
void getline(istream& ins, string& vote) {
string temp;
char v;
ins.get(v);
while (v != '\n' && !ins.eof()) {
temp += v;
ins.get(v);
if (v = '#') break;
}
vote = temp;
for (auto i = vote.begin(); i != vote.end(); ++i) {
if (*i = 'Y') Yvote++;
elseif (*i = 'N') Nvote++;
elseif (*i = 'P') Pvote++;
elseif (*i = 'A') Avote++;
elseif (*i = '#') exit(0);
}
};
//getVote function which takes each line of votes and determines the resul based on counts of each vote
string getVote(string& vote) {
int half = vote.size() / 2;
if (Avote >= half) return"need quorum\n";
elseif (Yvote > Nvote) return"yes\n";
elseif (Nvote > Yvote) return"no\n";
elseif (Yvote = Nvote) return"tie\n";
};
//main function calls getline function, pass the result and call getVote function, outputs result
int main() {
string line;
string result;
getline(cin, line);
result = getVote(line);
cout << result;
return 0;
}
Im getting an error that says: 'getVote': not all control paths return a value. And when i run it i can only input one line and always get 'need quorum' as an output then the program ens. Im trying to make it so it can read several lines until '#' is typed in then ouput a result for each line. Any ideas on how to fix these issues?
PS: i dont give too much attention to details so if it's something minor and idiotic....:)