Read a sequence of chars.

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?
Last edited on
std::getline()
this is what i have so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace 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++;
		else if (*i = 'N') Nvote++;
		else if (*i = 'P') Pvote++;
		else if (*i = 'A') Avote++;
		else if (*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";
	else if (Yvote > Nvote) return "yes\n";
	else if (Nvote > Yvote) return "no\n";
	else if (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....:)
Last edited on
Topic archived. No new replies allowed.