Commit ead5cb67 authored by Jared Sexton's avatar Jared Sexton
Browse files

Update Questions

parent 6fefa4b6
...@@ -11,10 +11,10 @@ using namespace std; ...@@ -11,10 +11,10 @@ using namespace std;
int main() { int main() {
Questions questionList; Questions questionList;
questionList.addSubQuestion(4); questionList.addSubQuestion(7);
questionList.addSubQuestion(4); questionList.addSubQuestion(7);
questionList.addSubQuestion(4); questionList.addSubQuestion(7);
questionList.addSubQuestion(4); questionList.addSubQuestion(7);
return 0; return 0;
} }
\ No newline at end of file
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
*/ */
#include "Questions.h" #include "Questions.h"
#include <iostream> #include <iostream> // For cout and cin
#include <cstdlib> #include <cstdlib> // For srand and rand
#include <ctime> // For time(0)
using namespace std; using namespace std;
void Questions::mainQuestionAsk(int level) { void Questions::mainQuestionAsk(int level) {
...@@ -41,7 +42,11 @@ bool Questions::countingQuestion(int level) { ...@@ -41,7 +42,11 @@ bool Questions::countingQuestion(int level) {
cout << "# "; cout << "# ";
} }
cout << "\nHow many symbols are there? "; cout << "\nHow many symbols are there? ";
cin >> answer; if(!(cin >> answer)) {
cin.clear();
cin.ignore(256,'\n');
answer = -1;
}
if(countTo == answer) { if(countTo == answer) {
cout << "Good job!\n"; cout << "Good job!\n";
return true; return true;
...@@ -52,56 +57,63 @@ bool Questions::countingQuestion(int level) { ...@@ -52,56 +57,63 @@ bool Questions::countingQuestion(int level) {
} }
bool Questions::addSubQuestion(int level) { bool Questions::addSubQuestion(int level) {
srand(time(0));
int maxNumber; int maxNumber;
switch(level) { switch(level) {
case 4: // 5's case 4: // 4's
maxNumber = rand() % 4; maxNumber = 4;
break; break;
case 5: case 5: // 5's
maxNumber = rand() % 5; maxNumber = 5;
break; break;
case 6: case 6: // 6's
maxNumber = rand() % 6; maxNumber = 6;
break; break;
case 7: case 7: // 7's
maxNumber = rand() % 7; maxNumber = 7;
break; break;
case 8: case 8: // 8's
maxNumber = rand() % 8; maxNumber = 8;
break; break;
case 9: case 9: // 9's'
maxNumber = rand() % 9; maxNumber = 9;
break; break;
case 10: case 10: // 10's
maxNumber = rand() % 10; maxNumber = 10;
break; break;
default: default:
cerr << "Please see your teacher about your current level.\n"; cerr << "Please see your teacher about your current level.\n";
break; break;
} }
// Initialize variables // Initialize variables
int userAnswer, correctAnswer; int userAnswer, correctAnswer;
int term1, term2; int term1, term2;
bool add = true; bool add = true;
// Determine if addition or subtraction
if((rand() % 2) == 0) {
add = false;
}
// Make sure term1 is greater than term2 within the desired range. // Make sure term1 is greater than term2 within the desired range.
do { do {
term1 = (rand() % maxNumber) + 1; term1 = (rand() % maxNumber) + 1;
term2 = (rand() % maxNumber) + 1; term2 = (rand() % maxNumber) + 1;
} while(term1 < term2); } while((term1 < term2) || ((term1 + term2) > maxNumber));
// Determine if addition or subtraction
// if((term1 + term2) < (maxNumber / 2)) {
// add = false;
// }
// NOT WORKING
// Ask the Question
if(add) { if(add) {
correctAnswer = term1 + term2; correctAnswer = term1 + term2;
cout << "\t" << term1 << endl; cout << "\t" << term1 << endl;
cout << "+\t" << term2 << endl; cout << "+\t" << term2 << endl;
cout << "-----------" << endl; cout << "-----------" << endl;
cout << "\t"; cout << "\t";
cin >> userAnswer; if(!(cin >> userAnswer)) {
cin.clear();
cin.ignore(256,'\n');
userAnswer = -1;
}
} }
else { else {
correctAnswer = term1 - term2; correctAnswer = term1 - term2;
...@@ -109,7 +121,11 @@ bool Questions::addSubQuestion(int level) { ...@@ -109,7 +121,11 @@ bool Questions::addSubQuestion(int level) {
cout << "-\t" << term2 << endl; cout << "-\t" << term2 << endl;
cout << "-----------" << endl; cout << "-----------" << endl;
cout << "\t"; cout << "\t";
cin >> userAnswer; if(!(cin >> userAnswer)) {
cin.clear();
cin.ignore(256,'\n');
userAnswer = -1;
}
} }
if(userAnswer == correctAnswer) { if(userAnswer == correctAnswer) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment