Created
November 13, 2019 09:53
-
-
Save meumairakram/fb0fb16d957d3ab4986ebe34f6af3c62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
using namespace std; | |
void printMenu() { | |
cout << "1: First Grade" << endl; | |
cout << "2: Second Grade Grade" << endl; | |
cout << "3: Third Grade" << endl; | |
cout << "4: Fourth Grade" << endl; | |
cout << "5: Fifth Grade" << endl; | |
} | |
int getMinRange (int grade) { | |
if(grade == 1) { | |
return 10; | |
} else if(grade == 2) { | |
return 100; | |
} else if (grade == 3) { | |
return 1000; | |
} else if (grade == 4) { | |
return 1000; | |
} else if (grade == 5) { | |
return 1000; | |
} | |
} | |
int getMaxRange (int grade) { | |
if(grade == 1) { | |
return 99; | |
} else if(grade == 2) { | |
return 999; | |
} else if (grade == 3) { | |
return 9999; | |
} else if (grade == 4) { | |
return 99999; | |
} else if (grade == 5) { | |
return 999999; | |
} | |
} | |
const char getRandomOperator() { | |
return "+-"[rand() % 2]; | |
} | |
int main() { | |
// declaring variables | |
int ques, sno, currentGrade, minR, maxR; | |
printMenu(); | |
cout << "Please Select a Grade: " ; | |
cin >> currentGrade; | |
minR = getMinRange(currentGrade); | |
maxR = getMaxRange(currentGrade); | |
cout << "Enter the number of questions you want to Generate: "; | |
cin >> ques; | |
int serial = 1; | |
for(int i = 0; i < ques; i++ ) { | |
int firstNum = rand() % (maxR - minR + 1) + minR; | |
int secNum = rand() % (maxR - minR + 1 ) + minR; | |
char opr = getRandomOperator(); | |
cout << serial << "."; | |
if(opr == '+') { | |
cout << "(" << firstNum << opr << secNum << ")" << ": ________ \t \t"; | |
} else if(opr == '-') { | |
cout << "(" << firstNum << opr << secNum << ")" << ": ________ \t \t"; | |
} | |
if((i+1) % 3 == 0) { | |
cout << endl; | |
} | |
serial++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment