I am having trouble with the output. So far I was trying the first two outputs (number of teams and number of runners on each team) so I haven't gotten to the other two outputs. I run the program and see that: 1. no matter what characters or how many I put, it doesn't change the calculations/output (number of teams or runners) and 2. something must be wrong with the while loop because the input repeats itself several times. The assignment is already almost 1 week late. Please help!
1. Move lines 22 and 23, inside the while statement, to where a line 27 and 28, would be.
2. You have a right parenthesis on line 26 which should be a left one '{'
3. You need another right parenthesis on line 136 and another on 137, to close the i for loop, and the while statement.
4. Without them, you restart the i loop line 139.
5. Remove lines 153 and 157.
quick update @here, when attempting an incorrect input, the input repeats about 4 times instead of just inquiring for input once after first error. Secondly, after i enter some characters, it loops the input about 3 times again(just the cout) then ONLY shows correct calculation after typing "done" to exit. Very odd :T
It's quite difficult to figure out what the reasons are for why it's not working correctly, when we can't see what changes you've done. Are you typing only capital letters for the input, etc.? Show us the changes, and we'll check it out. Thanks..
#include <iostream>
#include <cstdlib>
#include <string>
usingnamespace std;
bool validRace(int team[], int runnersperteam) //confirming equal amount of runners per team
{
for (int i = 0; i < 26; i++)
{
if (team[i] > 0)
if(team[i] != runnersperteam) // If any team has fewer or more runners
returnfalse;
}
returntrue;
}
int main()
{
string input;
int len;
int team[26] = {};
int score[26] = {};
while (input != "done")
{
cout << "Enter teams in the order they were placed. Each team must have equal amount of runners. 'done' to exit: " << endl;;
cin >> input;
len = input.length(); // Get string length for loop
if(input != "done")
{
for (int i = 0; i < len; i++)
{
switch(input[i])
{
case'A':
team[0]++;
score[0] += i + 1;// Not sure why this is for scoring
break;
case'B':
team[1]++;
score[1] += i + 1;
break;
case'C':
team[2]++;
score[2] += i + 1;
break;
case'D':
team[3]++;
score[3] += i + 1;
break;
case'E':
team[4]++;
score[4] += i + 1;
break;
case'F':
team[5]++;
score[5] += i + 1;
break;
case'G':
team[6]++;
score[6] += i + 1;
break;
case'H':
team[7]++;
score[7] += i + 1;
break;
case'I':
team[8]++;
score[8] += i + 1;
break;
case'J':
team[9]++;
score[9] += i + 1;
break;
case'K':
team[10]++;
score[10] += i + 1;
break;
case'L':
team[11]++;
score[11] += i + 1;
break;
case'M':
team[12]++;
score[12] += i + 1;
break;
case'N':
team[13]++;
score[13] += i + 1;
break;
case'O':
team[14]++;
score[14] += i + 1;
break;
case'P':
team[15]++;
score[15] += i + 1;
break;
case'Q':
team[16]++;
score[16] += i + 1;
break;
case'R':
team[17]++;
score[17] += i + 1;
break;
case'S':
team[18]++;
score[18] += i + 1;
break;
case'T':
team[19]++;
score[19] += i + 1;
break;
case'U':
team[20]++;
score[20] += i = 1;
break;
case'V':
team[21]++;
score[21] += i + 1;
break;
case'W':
team[22]++;
score[22] += i + 1;
break;
case'X':
team[23]++;
score[23] += i + 1;
break;
case'Y': team[24]++;
score[24] += i + 1;
break;
case'Z':
team[25]++;
score[26] += i + 1;
break;
}
}
} //end of for loop
} //end of while loop
int numTeams = 0;
for (int i = 0; i < 26; i++)
{
if (team[i] != 0)
{
numTeams+=team[i];
}
}
int runnersPerTeam;
for (int i = 0; i < 26; i++)// Check number of runners in first team of players
{
if (team[i] != 0)
{
runnersPerTeam = team[i];
i = 26;
}
}
if (validRace(team, runnersPerTeam)) //if equal amount of runners, outputs information
{
cout << "There are " << numTeams << " teams" << endl;
cout << "There are " << runnersPerTeam << " runners per team" << endl;
}
else
cout << "Not all teams have an equal amount of runners.." << endl;
return 0;
}