Almost finished writing a flash card program, everything worksperfectly except f
ID: 3617855 • Letter: A
Question
Almost finished writing a flash card program, everything worksperfectly except for division. Ideally, I would like it to only putout division combinations that come out to be whole numbers, whichI have no idea how to do. But for now, the main problem that I keephitting is that you cannot do integer division, but to keep therandom number generator from creating ridiculous decimal numbers,you have to force it to output integers. However, you cannot dointeger division in C++, it always returns 0. Can anyone devise away to convert the integer number output by the generator into afloat without printing anything to the window? Copy of this sectionof my code:int Division(int num1, int num2, float num3, int correctanswer)
{
while(num1 == 0 || num2 == 0)
{
num1 = rand() % (MAX_NUM - MIN_NUM + 1) +MIN_NUM;
num2 = rand() % (MAX_NUM - MIN_NUM + 1) +MIN_NUM;
}
cout << endl;
cout << num1 << " / " << num2<< " = ";
num3 = num2;
correctanswer = num1 / num3;
return correctanswer;
}
Thanks!
Explanation / Answer
please rate - thanks the answer is in red cast the double value--I also seeded the random numbergenerator #include #define MAX_NUM 100 #define MIN_NUM 0 using namespace std; int Division(int num1, int num2, float num3, intcorrectanswer); int main() {int num1; int num2; float num3; int correctanswer; srand(time(0)); for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.