Advertisement
pazryx

C9P1

May 1st, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7. void display_names();
  8. void player_info();
  9. void info_choose();
  10. void info_edit();
  11. struct playerData
  12. {
  13. string name;
  14. string position;
  15. int TD;
  16. int C;
  17. int PaY;
  18. int ReY;
  19. int RuY;
  20. };
  21. playerData Player[10];
  22. int index;
  23. int edit;
  24. char response;
  25.  
  26. int main()
  27. {
  28.  
  29. ifstream text;
  30. text.open("Input.txt");
  31.  
  32. for (index = 0; index < 10; index++)
  33. {
  34. text >> Player[index].name;
  35. text >> Player[index].position;
  36. text >> Player[index].TD;
  37. text >> Player[index].C;
  38. text >> Player[index].PaY;
  39. text >> Player[index].ReY;
  40. text >> Player[index].RuY;
  41. };
  42.  
  43. while(response != 'q')
  44. {
  45. index = 0;
  46. display_names();
  47.  
  48. cout << "\nSelect a player number to view info, or type q to quit.\n\n";
  49.  
  50. cin >> index;
  51. index -= 1;
  52.  
  53. player_info();
  54. };
  55.  
  56. cout << "Have a nice day!";
  57.  
  58. return 0;
  59. }
  60.  
  61. void display_names() // Shows the names in order.
  62. {
  63. int index;
  64. for (index = 0; index < 10; index++)
  65. {
  66. cout << index+1 << ". " << Player[index].name << "\n";
  67. };
  68.  
  69. }
  70.  
  71. void player_info() // Shows player's information.
  72. {
  73. while (index < 10)
  74. {
  75. cout << "\n";
  76. cout << Player[index].name << "\n";
  77. cout << Player[index].position << "\n";
  78. cout << Player[index].TD << "\n";
  79. cout << Player[index].C << "\n";
  80. cout << Player[index].PaY << "\n";
  81. cout << Player[index].ReY << "\n";
  82. cout << Player[index].RuY << "\n";
  83. cout << "Would you like to edit the player's information? [y - n]]\n";
  84.  
  85. cin >> response;
  86.  
  87. if(response == 'y')
  88. {
  89. info_choose();
  90. }
  91.  
  92. else
  93. {
  94. index = 10;
  95. response = ' ';
  96. };
  97. };
  98. }
  99.  
  100. void info_choose()
  101. {
  102. cout << "Which would you like to edit?\n";
  103. cout << "1. " << Player[index].name << "\n";
  104. cout << "2. " << Player[index].position << "\n";
  105. cout << "3. " << Player[index].TD << "\n";
  106. cout << "4. " << Player[index].C << "\n";
  107. cout << "5. " << Player[index].PaY << "\n";
  108. cout << "6. " << Player[index].ReY << "\n";
  109. cout << "7. " << Player[index].RuY << "\n";
  110.  
  111. cin >> edit;
  112.  
  113. switch (edit)
  114. {
  115. case 1:
  116. cout << "Type in the new name.\n";
  117. cin >> Player[index].name;
  118. break;
  119. case 2:
  120. cout << "Type in new position.\n";
  121. cin >> Player[index].position;
  122. break;
  123. case 3:
  124. cout << "Type in the new number.\n";
  125. cin >> Player[index].TD;
  126. break;
  127. case 4:
  128. cout << "Type in the new number.\n";
  129. cin >> Player[index].C;
  130. break;
  131. case 5:
  132. cout << "Type in the new number.\n";
  133. cin >> Player[index].PaY;
  134. break;
  135. case 6:
  136. cout << "Type in the new number.\n";
  137. cin >> Player[index].ReY;
  138. break;
  139. case 7:
  140. cout << "Type in the new number.\n";
  141. cin >> Player[index].RuY;
  142. break;
  143.  
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement