Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Lab Exercise 6.1
- SoccerTeams.cpp
- This program will calculate the number of soccer teams
- that a youth league may create from the number of
- available players. Input validation is required using
- while loops.
- Use a loop to validate the user input for how many
- players per team; The acceptable range should be
- 9 to 15 players. The loop should continue until
- the user enters a valid number.
- Use a similar loop to validate the user input for
- how many players are available; The acceptable range
- should be 1 or more avaialable players.
- */
- #include <iostream>
- using namespace std;
- int main()
- {
- int players; // Number of available players
- int teamPlayers; // Number of desired players per team
- int numTeams; // Number of teams
- int leftOver; // Number of players left over
- // Get the number of players per team.
- cout << "How many players do you wish per team?\n";
- cout << "(Enter a value in the range 9 - 15): ";
- cin >> teamPlayers;
- // TODO: Validate the input using a while loop.
- cout << endl;
- // Get the number of players available.
- cout << "How many players are available? ";
- cin >> players;
- // TODO: Validate the input using a while loop.
- cout << endl;
- // Calculate the number of teams.
- numTeams = players / teamPlayers;
- // Calculate the number of leftover players.
- leftOver = players % teamPlayers;
- // Display the results.
- cout << "There will be " << numTeams << " teams with ";
- cout << leftOver << " players left over.\n";
- return 0;
- }
- /* Sample:
- How many players do you wish per team?
- (Enter a value in the range 9 - 15): 8
- You should have at least 9 but no
- more than 15 per team.
- How many players do you wish per team? 16
- You should have at least 9 but no
- more than 15 per team.
- How many players do you wish per team? 9
- How many players are available? 0
- Please enter a positive number: 50
- There will be 5 teams with 5 players left over.
- */
Add Comment
Please, Sign In to add comment