Advertisement
Guest User

Untitled

a guest
Sep 8th, 2014
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6.  
  7. const int numItems = 6;
  8. const string shopItemNames[numItems] = { "Boots", "Swords", "Helmets", "Kittens", "Poleaxes", "Leggings" };
  9. void printShop();
  10. void printInventory(int playerInventory[numItems]);
  11. void stringUpper(string &s);
  12. bool buyItems(int playerInventory[numItems]);
  13. int main()
  14. {
  15. int playerInventory[numItems] = {5,3,6,1,0,0};
  16.  
  17. bool isDone = false;
  18. cout << "***Welcome to the Item Shop!***" << endl<<endl;
  19.  
  20. while (isDone == false){
  21. system("cls");
  22. printShop();
  23. printInventory(playerInventory);
  24. isDone = buyItems(playerInventory);
  25. cout << "\n\n\n";
  26. printInventory(playerInventory);
  27. cout << "\n\n\n";
  28.  
  29. }
  30.  
  31. system("PAUSE");
  32. return 0;
  33. }
  34. void printInventory(int playerInventory[numItems])
  35. {
  36. cout << " Your inventory is:" << endl<<endl;
  37. for (int i = 0; i < numItems; i++){
  38. if (playerInventory[i]>0){
  39. cout << " " << playerInventory[i] <<" x " << shopItemNames[i] << endl << endl;
  40. }
  41. }
  42.  
  43. }
  44.  
  45.  
  46. void printShop()
  47. {
  48. cout << "Here's what we have in stock today..." << endl << endl;
  49. for (int i = 0; i < numItems; i++){
  50. cout << i+1 << ": "<< shopItemNames[i] << endl;
  51. }
  52. }
  53.  
  54. bool buyItems(int playerInventory[numItems])
  55.  
  56. {
  57. int inventoryCheck;
  58. string inputInitial;
  59. int inputBuy;
  60. int inputBuyMultiple;
  61. int inputSell;
  62. int inputSellMultiple;
  63.  
  64. for (int i = 0; i < 1; i){
  65. cout << "\n\nWould you like to buy or sell an item? (B or S) : ";
  66. cin >> inputInitial;
  67. stringUpper(inputInitial);
  68. if (inputInitial == "B"){
  69. cout << "\n\nWhat would you like to buy? Enter a number (1 - " << numItems << ") or - 1 to quit:";
  70. cin >> inputBuy;
  71. if (inputBuy == -1){
  72. return true;
  73.  
  74. }
  75. if (inputBuy - 1 < 0 || inputBuy - 1 >= numItems) {
  76. cout << "Not a valid entry!" << endl;
  77. cout << "\n\n\n";
  78. return false;
  79. }
  80. cout << "\n\nHow many would you like? Enter a number: ";
  81. cin >>inputBuyMultiple;
  82. for (int l = 0; l < inputBuyMultiple; l++){
  83. playerInventory[inputBuy - 1]++; //adds to inventory
  84. }
  85. return false;
  86. }
  87. if (inputInitial == "S"){
  88. cout << "\n\nWhat would you like to Sell? Enter a number between 1 and " << numItems << " or enter - 1 to quit:";
  89. cin >> inputSell;
  90. if (inputSell <= numItems){
  91.  
  92. inventoryCheck = playerInventory[inputSell - 1];
  93. if (inventoryCheck >= 1){
  94. if (inputSell == -1){
  95. return true;
  96.  
  97. }
  98. if (inputSell - 1 < 0 || inputSell - 1 >= numItems) {
  99. cout << "\n\nNot a valid entry!" << endl;
  100. cout << "\n\n\n";
  101. return false;
  102. }
  103. if (inventoryCheck == 1) {
  104. playerInventory[inputSell - 1]--; //subs from inventory
  105. return false;
  106. }
  107. if (inventoryCheck >= 1) {
  108. cout << "\n\n\n You have " << inventoryCheck << " " << shopItemNames[i] << ". \n\n\nHow many would you like to sell? Enter a number between 1 and " << inventoryCheck << ": ";
  109. cin >> inputSellMultiple;
  110. for (int k = 0; k < inputSellMultiple; k++){
  111.  
  112. playerInventory[inputSell - 1]--; //subs from inventory
  113. }
  114. return false;
  115. }
  116. Sleep(2300);
  117. return false;
  118. }
  119.  
  120.  
  121. }
  122. }
  123.  
  124.  
  125. cout << "\n\n\n\n\n Not a valid entry!\n\n\n\n\n" << endl;
  126. Sleep(2300);
  127. return false;
  128.  
  129. }
  130. Sleep(2300);
  131. return false;
  132. }
  133. void stringUpper(string &s)
  134. {
  135. for (unsigned int l = 0; l < s.length(); l++)
  136. {
  137. s[l] = toupper(s[l]);
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement