Commit ead5cb67 authored by Jared Sexton's avatar Jared Sexton

Update Questions

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