From 7c5e3e5a8a279a6d49a2a0ca2b033dc590f5a3c5 Mon Sep 17 00:00:00 2001 From: wjoe Date: Tue, 15 May 2012 14:32:52 +0100 Subject: v0.61 - Added some error checking to 8ball --- blarandom.cpp | 16 +++++++++++++--- 1 file 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 { -- cgit v1.2.3