Advertisement
pazryx

C9P1 v2

May 1st, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 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, then enter a number again or type q to quit.\n\n";
  49.  
  50. cin >> index;
  51. cin >> response;
  52. index -= 1;
  53. if (response != 'q')
  54. {
  55. player_info();
  56. }
  57. };
  58.  
  59. cout << "Have a nice day!";
  60.  
  61. return 0;
  62. }
  63.  
  64. void display_names() // Shows the names in order.
  65. {
  66. int index;
  67. for (index = 0; index < 10; index++)
  68. {
  69. cout << index+1 << ". " << Player[index].name << "\n";
  70. };
  71.  
  72. }
  73.  
  74. void player_info() // Shows player's information.
  75. {
  76. while (index < 10)
  77. {
  78. cout << "\n";
  79. cout << Player[index].name << "\n";
  80. cout << Player[index].position << "\n";
  81. cout << Player[index].TD << "\n";
  82. cout << Player[index].C << "\n";
  83. cout << Player[index].PaY << "\n";
  84. cout << Player[index].ReY << "\n";
  85. cout << Player[index].RuY << "\n";
  86. cout << "Would you like to edit the player's information? [y - n]]\n";
  87.  
  88. cin >> response;
  89.  
  90. if(response == 'y')
  91. {
  92. info_choose();
  93. }
  94.  
  95. else
  96. {
  97. index = 10;
  98. response = ' ';
  99. };
  100. };
  101. }
  102.  
  103. void info_choose()
  104. {
  105. cout << "Which would you like to edit?\n";
  106. cout << "1. " << Player[index].name << "\n";
  107. cout << "2. " << Player[index].position << "\n";
  108. cout << "3. " << Player[index].TD << "\n";
  109. cout << "4. " << Player[index].C << "\n";
  110. cout << "5. " << Player[index].PaY << "\n";
  111. cout << "6. " << Player[index].ReY << "\n";
  112. cout << "7. " << Player[index].RuY << "\n";
  113.  
  114. cin >> edit;
  115.  
  116. switch (edit)
  117. {
  118. case 1:
  119. cout << "Type in the new name.\n";
  120. cin >> Player[index].name;
  121. break;
  122. case 2:
  123. cout << "Type in new position.\n";
  124. cin >> Player[index].position;
  125. break;
  126. case 3:
  127. cout << "Type in the new number.\n";
  128. cin >> Player[index].TD;
  129. break;
  130. case 4:
  131. cout << "Type in the new number.\n";
  132. cin >> Player[index].C;
  133. break;
  134. case 5:
  135. cout << "Type in the new number.\n";
  136. cin >> Player[index].PaY;
  137. break;
  138. case 6:
  139. cout << "Type in the new number.\n";
  140. cin >> Player[index].ReY;
  141. break;
  142. case 7:
  143. cout << "Type in the new number.\n";
  144. cin >> Player[index].RuY;
  145. break;
  146.  
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement