Generic Miner - v0.0.2


/ Published in: C++
Save to your folder(s)

Just a simple console program that mines ore or displays it depending on the users choice. This is the second version of the script using case and if statements. v0.0.1 had some issues. I\'m sure there is a better way to implement this, but I\'m still leaning .


Copy this code and paste it in your HTML
  1. // The generic miner v0.0.2
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <ctime>
  7.  
  8. int main()
  9. {
  10. using namespace std;
  11.  
  12. cout << "*** Choose an option. ***\n\n";
  13. cout << "1: - Mine\n";
  14. cout << "2: - Show Ore\n";
  15. cout << "3: - Exit\n\n";
  16.  
  17. int choice;
  18. int totalOre = 0;
  19.  
  20. do
  21. {
  22. cout << "Choice: ";
  23. cin >> choice;
  24.  
  25. // Roll a 20 sided dice to check if the player finds ore.
  26. srand(time(0));
  27. int randNum = rand();
  28. int randOre = (randNum % 20) + 1;
  29.  
  30. switch (choice)
  31. {
  32. case 1:
  33. if (choice == 1 && randOre > 10)
  34. {
  35. cout << randOre << ": Rolled\n" << "*** You found ore! ***\n\n";
  36. ++totalOre;
  37. }
  38. else
  39. {
  40. cout << "Nothing was found\n\n";
  41. }
  42. break;
  43.  
  44. case 2:
  45. if (choice == 2 && totalOre > 0)
  46. {
  47. cout << "Total Ore: " << totalOre << "\n\n";
  48. }
  49. else
  50. {
  51. cout << "You have no ore. Try to mine...\n\n";
  52. }
  53. break;
  54.  
  55. default:
  56. cout << "Exiting...\n";
  57. }
  58. } while (choice == 1 || choice == 2);
  59.  
  60. cin.clear();
  61. cin.ignore(255, '\n');
  62. cin.get();
  63. return 0;
  64. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.