/ Published in: C++
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 .
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// The generic miner v0.0.2 #include <iostream> #include <string> #include <cstdlib> #include <ctime> int main() { using namespace std; cout << "*** Choose an option. ***\n\n"; cout << "1: - Mine\n"; cout << "2: - Show Ore\n"; cout << "3: - Exit\n\n"; int choice; int totalOre = 0; do { cout << "Choice: "; cin >> choice; // Roll a 20 sided dice to check if the player finds ore. srand(time(0)); int randNum = rand(); int randOre = (randNum % 20) + 1; switch (choice) { case 1: if (choice == 1 && randOre > 10) { cout << randOre << ": Rolled\n" << "*** You found ore! ***\n\n"; ++totalOre; } else { cout << "Nothing was found\n\n"; } break; case 2: if (choice == 2 && totalOre > 0) { cout << "Total Ore: " << totalOre << "\n\n"; } else { cout << "You have no ore. Try to mine...\n\n"; } break; default: cout << "Exiting...\n"; } } while (choice == 1 || choice == 2); cin.clear(); cin.ignore(255, '\n'); cin.get(); return 0; }