fork download
  1. //Jonathan Estrada CSC5 Chapter 11, P.646, #6
  2. /*******************************************************************************
  3.  * GET TEAM STATS
  4.  * _____________________________________________________________________________
  5.  * This program gets jerasy numbers, name, and points scored, then displays the
  6.  * information on a table. The program will also display the player who scored
  7.  * the most points and the total points for the team.
  8.  * _____________________________________________________________________________
  9.  * INPUT
  10.  * size : size of team
  11.  * playerName : player name
  12.  * playerNum : player jerasy number
  13.  * points : points scired
  14.  *
  15.  * OUTPUT
  16.  * totalPoints : total points of team
  17.  * maxindex : player with the most individual points scored
  18.  *
  19.  * ****************************************************************************/
  20. #include <iostream>
  21. #include <string>
  22. using namespace std;
  23.  
  24. struct team
  25. {
  26. string playerName;
  27. int playerNum;
  28. int points;
  29. };
  30.  
  31. int main() {
  32. int size = 11;
  33. int totalPoints = 0;
  34. int maxPoints = 0, maxindex = 0;
  35. team player[size];
  36.  
  37. for(int i= 0; i < size; i++)
  38. {
  39. cout << "Player Name: ";
  40. getline(cin, player[i].playerName);
  41.  
  42. cout << "Player Number: ";
  43. cin >> player[i].playerNum;
  44. cin.ignore();
  45.  
  46. cout << "Player Points: ";
  47. cin >> player[i].points;
  48. while(player[i] > 0)
  49. {
  50. cout << "Invalid cannot be less than 0." << endl;
  51. cout << "Player Points: ";
  52. cin >> player[i].points;
  53. }
  54. cin.ignore();
  55.  
  56. totalPoints += player[i].points;
  57.  
  58. if(player[i].points > maxPoints)
  59. {
  60. maxPoints = player[i].points;
  61. maxindex = i;
  62. }
  63. }
  64. cout << "Players Information for the Team" << endl;
  65. cout << "Number " << " Name " << " Points" << endl;
  66. cout << "--------------------------------" << endl;
  67.  
  68. for(int i= 0; i < size; i++)
  69. {
  70. cout << player[i].playerNum << "|" << player[i].playerName << "|"
  71. << player[i].points << endl;
  72. }
  73. cout << "Total points for every player is " << totalPoints << endl;
  74. cout << "\nPlayer with the most points was: " << endl;
  75. cout << player[maxindex].playerNum << "|" << player[maxindex].playerName << "|"
  76. << player[maxindex].points << endl;
  77.  
  78.  
  79. return 0;
  80. }
Success #stdin #stdout 0.01s 5272KB
stdin
John Doe
10
15
Jane Smith
11
20
Jim Brown
12
30
Emily White
13
25
Tom Green
14
22
Sara Blue
15
18
Mike Black
16
12
Lucy Gray
17
27
Harry Potter
18
33
Hermione Granger
19
28
Ron Weasley
20
24
stdout
Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Player Name: Player Number: Player Points: Players Information for the Team
Number  Name  Points
--------------------------------
10|John Doe|15
11|Jane Smith|20
12|Jim Brown|30
13|Emily White|25
14|Tom Green|22
15|Sara Blue|18
16|Mike Black|12
17|Lucy Gray|27
18|Harry Potter|33
19|Hermione Granger|28
20|Ron Weasley|24
Total points for every player is 254

Player with the most points was: 
18|Harry Potter|33