Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Math test, first shot
- //Start by including libraries
- #include <iostream>
- #include <ctime>
- using namespace std;
- int addquiz(int a)
- {
- //Create multiplier to use in first while loop
- //First while loop will change the value of multiplier, which will be used in later rand() command
- int multiplier = 10;
- int difficulty = 0;
- int timesdone = 0;
- int value1;
- int value2;
- int guess;
- int numbercorrect = 0;
- //While loop to change difficulty
- while (difficulty != a)
- {
- difficulty++;
- if (difficulty !=a) multiplier*=10;
- }
- //Second while loop, this one is just used to do 10 quizzes
- while (timesdone < 10)
- {
- timesdone++;
- //Setting values for quiz
- value1 = rand() %multiplier+1;
- value2 = rand() %multiplier+1;
- cout << "What is " << value1 << " + " << value2 << "?" << endl;
- cin >> guess;
- if (guess == value1+value2)
- {
- numbercorrect++;
- cout << endl;
- cout << endl;
- cout << "That is correct!" << endl;
- }
- else
- {
- cout << endl;
- cout << endl;
- cout << "That is incorrect." << endl;
- }
- if (timesdone < 10)
- {
- cout << "Next question." << endl;
- cout << endl;
- }
- }
- return numbercorrect;
- }
- int subquiz(int b)
- {
- //Create multiplier to use in first while loop
- //First while loop will change the value of multiplier, which will be used in later rand() command
- int difficulty = 0;
- int multiplier = 10;
- int timesdone = 0;
- int value1;
- int value2;
- int value3; //Value 3 is necessary only for subtraction and division
- int guess;
- int numbercorrect = 0;
- //While loop to change difficulty
- while (difficulty != b)
- {
- difficulty++;
- if (difficulty !=b) multiplier*=10;
- }
- //Second while loop, this one is just used to do 10 quizzes
- while (timesdone < 10)
- {
- timesdone++;
- //Setting values for quiz
- value1 = rand() %multiplier+1;
- value2 = rand() %multiplier+1;
- value3 = value1 + value2;
- cout << "What is " << value3 << " - " << value2 << "?" << endl;
- cin >> guess;
- if (guess == value3-value2)
- {
- numbercorrect++;
- cout << endl;
- cout << endl;
- cout << "That is correct!" << endl;
- }
- else
- {
- cout << endl;
- cout << endl;
- cout << "That is incorrect." << endl;
- }
- if (timesdone < 10)
- {
- cout << "Next question." << endl;
- cout << endl;
- }
- }
- return numbercorrect;
- }
- int multquiz(int c)
- {
- //Create multiplier to use in first while loop
- //First while loop will change the value of multiplier, which will be used in later rand() command
- int multiplier = 1;
- int difficulty = 0;
- int timesdone = 0;
- int value1;
- int value2;
- int guess;
- int numbercorrect = 0;
- //While loop to change difficulty
- while (difficulty != c)
- {
- if (difficulty !=c) multiplier*=10;
- difficulty++;
- }
- //Second while loop, this one is just used to do 10 quizzes
- while (timesdone < 10)
- {
- timesdone++;
- //Setting values for quiz
- value1 = rand() %multiplier+1;
- value2 = rand() %multiplier+1;
- cout << "What is " << value1 << " x " << value2 << "?" << endl;
- cin >> guess;
- if (guess == value1*value2)
- {
- numbercorrect++;
- cout << endl;
- cout << endl;
- cout << "That is correct!" << endl;
- }
- else
- {
- cout << endl;
- cout << endl;
- cout << "That is incorrect." << endl;
- }
- if (timesdone < 10)
- {
- cout << "Next question." << endl;
- cout << endl;
- }
- }
- return numbercorrect;
- }
- int divquiz(int d)
- {
- //Create multiplier to use in first while loop
- //First while loop will change the value of multiplier, which will be used in later rand() command
- int multiplier = 1;
- int difficulty = 0;
- int timesdone = 0;
- int value1;
- int value2;
- int value3;
- int guess;
- int numbercorrect = 0;
- //While loop to change difficulty
- while (difficulty != d)
- {
- difficulty++;
- if (difficulty !=d) multiplier*=10;
- }
- //Second while loop, this one is just used to do 10 quizzes
- while (timesdone < 10)
- {
- timesdone++;
- //Setting values for quiz
- value1 = rand() %multiplier+1;
- value2 = rand() %multiplier+1;
- value3 = value1 * value2;
- cout << "What is " << value3 << " + " << value2 << "?" << endl;
- cin >> guess;
- if (guess == value3/value2)
- {
- numbercorrect++;
- cout << endl;
- cout << endl;
- cout << "That is correct!" << endl;
- }
- else
- {
- cout << endl;
- cout << endl;
- cout << "That is incorrect." << endl;
- }
- if (timesdone < 10)
- {
- cout << "Next question." << endl;
- cout << endl;
- }
- }
- return numbercorrect;
- }
- int main()
- {
- //Declare variables
- int quizchoice = 0;
- int quizdifficulty = 0;
- bool properchoice=false;
- int timescorrect;
- //Seed random number command
- srand(time(NULL));
- //Intro and ask for quiz choice
- cout << "This is the math test. Created by Cockgoblin." << endl;
- cout << "Which test would you like to do?" << endl;
- cout << "1. Addition" << endl;
- cout << "2. Subtraction" << endl;
- cout << "3. Multiplication " << endl;
- cout << "4. Division" << endl;
- while (properchoice==false)
- {
- cin >> quizchoice;
- //Check to see if answer is valid
- if (quizchoice >= 1 && quizchoice <= 4) properchoice = true;
- if (properchoice==false)
- {
- cout << "Sorry, that was an invalid command." << endl;
- cout << endl;
- }
- }
- //Reset properchoice boolean for quizdifficulty check
- properchoice = false;
- //Ask for quiz difficulty
- cout << endl;
- cout << endl;
- cout << "What difficulty would you like?" << endl;
- cout << "1. Elementary" << endl;
- cout << "2. Junior High School" << endl;
- cout << "3. High School" << endl;
- while (properchoice==false)
- {
- cin >> quizdifficulty;
- //Check to see if answer is valid
- if (quizdifficulty >= 1 && quizdifficulty <= 3) properchoice = true;
- if (properchoice==false)
- {
- cout << "Sorry, that was an invalid command." << endl;
- cout << endl;
- }
- }
- //Call for specific quiz function
- //I know I can use an if/else for 3 and 4, don't care
- if (quizchoice == 1) timescorrect = addquiz(quizdifficulty);
- if (quizchoice == 2) timescorrect = subquiz(quizdifficulty);
- if (quizchoice == 3) timescorrect = multquiz(quizdifficulty);
- if (quizchoice == 4) timescorrect = divquiz(quizdifficulty);
- cout << "You got " << timescorrect << " out of 10 questions right. :)" << endl;
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment