From f5b5b79a70d2cdbaf021072ba5ed10127bcb23f2 Mon Sep 17 00:00:00 2001 From: wjoe Date: Tue, 15 May 2012 15:15:28 +0100 Subject: v0.62 - Fixed 8ball handling more than 1 word --- blarandom.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/blarandom.cpp b/blarandom.cpp index aa6edfd..2bbe7e3 100644 --- a/blarandom.cpp +++ b/blarandom.cpp @@ -28,6 +28,7 @@ v0.5 - Added 8ball preset v0.6 - Can now use count with presets v0.61 - Added error handling for 8ball, removed ability to count + v0.62 - Fixed 8ball handling more than one word */ @@ -40,15 +41,15 @@ int main() { - std::string version = "0.61"; + std::string version = "0.62"; RandomLib::Random r; // Create r r.Reseed(); // and give it a unique seed - char input[100]; - - fgets(input, 100, stdin); + char input[1000]; + const int N_ARGS = 30; + fgets(input, 1000, stdin); std::string strInput = input; - std::string args[30] = { "" }; + std::string args[N_ARGS] = { "" }; std::istringstream iss(strInput); @@ -56,7 +57,7 @@ int main() { int max = INT_MIN; int count = 1; - for(int i = 0; i < 3; i++) { + for(int i = 0; i < N_ARGS; i++) { iss >> args[i]; } @@ -113,16 +114,22 @@ int main() { } else if (!args[0].compare("8ball")) { min = 0; max = 17; + count = 1; eightball = true; std::string question = ""; - for (int i = 1; i < 30; i++) { + for (int i = 1; i < N_ARGS; i++) { question += args[i]; } - if (question.length() == 0 || - question.substr(question.length()-1, 1).compare("?")) { + if (question.length() > 0) { + if (question.substr(question.length()-1, 1).compare("?")) { + std::cout << "Ask a question!" << std::endl; + return 1; + } + } else { std::cout << "Ask a question!" << std::endl; return 1; } + } if (coin || dice || letter || d20) { @@ -175,7 +182,6 @@ int main() { strResult = ss.str(); } std::cout << strResult << " "; - } std::cout << std::endl; -- cgit v1.2.3