summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwjoe <joe@lc8n.com>2012-05-15 14:32:52 +0100
committerwjoe <joe@lc8n.com>2012-05-15 14:32:52 +0100
commit7c5e3e5a8a279a6d49a2a0ca2b033dc590f5a3c5 (patch)
tree788e7c7aff1abc19149c23485c2a13ee2ccd4d14
parent3e1cfaf3cd8abd25b6df740dccf5e606aa182711 (diff)
v0.61 - Added some error checking to 8ball
-rw-r--r--blarandom.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/blarandom.cpp b/blarandom.cpp
index 1d99e05..aa6edfd 100644
--- a/blarandom.cpp
+++ b/blarandom.cpp
@@ -27,6 +27,7 @@
v0.4 - Added coin & dice presets
v0.5 - Added 8ball preset
v0.6 - Can now use count with presets
+ v0.61 - Added error handling for 8ball, removed ability to count
*/
@@ -39,7 +40,7 @@
int main() {
- std::string version = "0.6";
+ std::string version = "0.61";
RandomLib::Random r; // Create r
r.Reseed(); // and give it a unique seed
@@ -47,7 +48,7 @@ int main() {
fgets(input, 100, stdin);
std::string strInput = input;
- std::string args[10] = { "" };
+ std::string args[30] = { "" };
std::istringstream iss(strInput);
@@ -113,9 +114,18 @@ int main() {
min = 0;
max = 17;
eightball = true;
+ std::string question = "";
+ for (int i = 1; i < 30; i++) {
+ question += args[i];
+ }
+ if (question.length() == 0 ||
+ question.substr(question.length()-1, 1).compare("?")) {
+ std::cout << "Ask a question!" << std::endl;
+ return 1;
+ }
}
- if (coin || dice || letter || d20 || eightball) {
+ if (coin || dice || letter || d20) {
if (args[1].empty()) {
count = 1;
} else {