text: /***************************************************************** Volleyball version 1 This is what you might have as "backyard rules" of volleyball. A game is a series of rallies. Each rally has a winning team, and the winning team scores one point. The first team to 10 points is the winner. This program should start by reading in the names of the two teams, and then go into a while loop reading in the name of which team wins each rally. After each rally, print out the current score, and when someone reaches 10 points, the program should print out the winning team. *****************************************************************/ #include <iostream> #include <string> using namespace std; int main() { // read in team names string name1, name2; cout << "Team 1 name: "; cin >> name1; cout << "Team 2 name: "; cin >> name2; cout << endl; // set up scores int score1 = 0; // current score of team 1 int score2 = 0; // current score of team 2 int winat = 10; // how many points needed to win // Stores who wins each rally // It's at the outer scope so we can announce the winner at the end! string winname; // play the game until it's over while (score1 < winat && score2 < winat) { // get winner of next rally cout << "Winner of next rally: "; cin >> winname; // update the appropriate score if (winname == name1) { score1 = score1 + 1; } else if (winname == name2) { score2 = score2 + 1; } else { cout << "Invalid team name; please try again." << endl; } // print out current scores cout << name1 << ": " << score1 << ", " << name2 << ": " << score2 << endl; } // print out who won cout << endl << winname << " is the winner!" << endl; return 0; }