Can anyone tell me why my function won't print the first letter of names after the first one? This is my code.
void plusScores(ifstream& in, ostream& out)
{
string name;
char score;
int plus = 0;
int minus = 0;;
double sum;
double percent;
while (getline(in, name))
{
while (in >> score && (score == '+' || score == '-'))
{
if (score == '+')
plus++;
else if (score == '-')
minus++;
}
sum = plus + minus;
percent = (plus / sum) * 100;
out << fixed << showpoint << setprecision(1);
out << name << ": " << percent << "% plus" << endl;
plus = 0;
minus = 0;
}
}
My output should look like this:
Kane, Erica: 40.0% plus
Chandler, Adam: 75.0% plus
Martin, Jake: 100.0% plus
Dillon, Amanda: 62.5% plus
Instead I get this:
Kane, Erica: 40.0% plus
handler, Adam: 75.0% plus
artin, Jake: 100.0% plus
illon, Amanda: 62.5% plus
The text file it's reading looks like this:
Kane, Erica
--+-+
Chandler, Adam
++-+
Martin, Jake
+++++++
Dillon, Amanda
++-++-+-