fork download
  1. //Giana Osorio CSC5 Chapter 11, p.646, #6
  2. //
  3. /******************************************************************************
  4.  *
  5.  * CALCULATE SOCCER TEAM TOTAL POINTS
  6.  * ___________________________________________________________________________
  7.  * This program will accept 12 different soccer players and recieve the players
  8.  * number as well as goals scored. Each players name, number, and goals will
  9.  * then be displayed. The teams total points will be calulated and displayed
  10.  * along with the number and player who scored the most goals.
  11.  * ____________________________________________________________________________
  12.  * INPUT
  13.  * players[] : Holds soccer players information
  14.  *
  15.  * OUTPUT
  16.  * totalGoals : Total Goals the team has made
  17.  *****************************************************************************/
  18. #include <iostream>
  19. #include <iomanip>
  20. using namespace std;
  21.  
  22. //STRUCTURE
  23. struct PlayersInfo
  24. {
  25. string name;
  26. int number;
  27. int goals;
  28. };
  29. int main()
  30. {
  31. const int size = 12; //ARRAY SIZE DECLERATION
  32. PlayersInfo players[size]; //INPUT - Holds soccer players information
  33. int totalGoals = 0; //OUTPUT - Total Goals the team has made
  34.  
  35. //GET SOCCER PLAYERS INFO
  36. for (int i = 0; i < size; i++)
  37. {
  38. cout << "Please enter a player's name: \n";
  39. cin >> players[i].name;
  40. cout << "Please enter their jersey number: \n";
  41. cin >> players[i].number;
  42. cout << "Please enter the amount of goals they have scored: \n";
  43. cin >> players[i].goals;
  44.  
  45. //RUNNING TOTAL OF THE TEAMS GOALS
  46. totalGoals += players[i].goals;
  47. }
  48.  
  49. //DISPLAY TEAM DATA
  50.  
  51. cout << "PLAYER" << setw(15) << "NUMBER" << setw(15) << "GOALS" << endl;
  52. for (int i = 0; i < size; i++)
  53. {
  54. cout << right << setw(6) << players[i].name << setw(15) << players[i].number
  55. << setw(15) << players[i].goals << endl;
  56. }
  57. cout << "The team has scored a total of " << totalGoals
  58. << " goals this season!";
  59. return 0;
  60. }
Success #stdin #stdout 0.01s 5280KB
stdin
Davide 1 2
Theo 2 3
Fikayo  3 2
Simon 4 2 
Giana 5 3
Olivie 6 5
Franc 7 2
Rafael 8 3
Rade 9 2
Mike 10 3
Yacine 11 6
Myrna 12 8
stdout
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
Please enter a player's name: 
Please enter their jersey number: 
Please enter the amount of goals they have scored: 
PLAYER         NUMBER          GOALS
Davide              1              2
  Theo              2              3
Fikayo              3              2
 Simon              4              2
 Giana              5              3
Olivie              6              5
 Franc              7              2
Rafael              8              3
  Rade              9              2
  Mike             10              3
Yacine             11              6
 Myrna             12              8
The team has scored a total of 41 goals this season!