Guest User

Untitled

a guest
Dec 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. /* Lab Exercise 6.1
  2. SoccerTeams.cpp
  3.  
  4. This program will calculate the number of soccer teams
  5. that a youth league may create from the number of
  6. available players. Input validation is required using
  7. while loops.
  8.  
  9. Use a loop to validate the user input for how many
  10. players per team; The acceptable range should be
  11. 9 to 15 players. The loop should continue until
  12. the user enters a valid number.
  13.  
  14. Use a similar loop to validate the user input for
  15. how many players are available; The acceptable range
  16. should be 1 or more avaialable players.
  17. */
  18.  
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. int players; // Number of available players
  25. int teamPlayers; // Number of desired players per team
  26. int numTeams; // Number of teams
  27. int leftOver; // Number of players left over
  28.  
  29. // Get the number of players per team.
  30. cout << "How many players do you wish per team?\n";
  31. cout << "(Enter a value in the range 9 - 15): ";
  32. cin >> teamPlayers;
  33.  
  34. // TODO: Validate the input using a while loop.
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. cout << endl;
  44.  
  45. // Get the number of players available.
  46. cout << "How many players are available? ";
  47. cin >> players;
  48.  
  49. // TODO: Validate the input using a while loop.
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. cout << endl;
  57.  
  58. // Calculate the number of teams.
  59. numTeams = players / teamPlayers;
  60.  
  61. // Calculate the number of leftover players.
  62. leftOver = players % teamPlayers;
  63.  
  64. // Display the results.
  65. cout << "There will be " << numTeams << " teams with ";
  66. cout << leftOver << " players left over.\n";
  67.  
  68. return 0;
  69. }
  70.  
  71. /* Sample:
  72.  
  73. How many players do you wish per team?
  74. (Enter a value in the range 9 - 15): 8
  75. You should have at least 9 but no
  76. more than 15 per team.
  77. How many players do you wish per team? 16
  78. You should have at least 9 but no
  79. more than 15 per team.
  80. How many players do you wish per team? 9
  81.  
  82. How many players are available? 0
  83. Please enter a positive number: 50
  84.  
  85. There will be 5 teams with 5 players left over.
  86.  
  87. */
Add Comment
Please, Sign In to add comment