Random generation of arithmetic questions within 30 100

Source: Internet
Author: User

Design ideas:

1. Randomly generate two random numbers using random number method

1.1 Control random number within 100

1.2 Random number is not equal to 0

2. Problems with operators

1.1 The 1,2,3,4 obtained by using redundancy means "+", "-", "*", "/", respectively.

3. How to express a true score

1.1 using random number method to generate two random numbers

1.2 Compare the size of the generated random number, small as the numerator, large as the denominator, get the true fraction

4, the output operation results, with 1, 2 for the integer operation and a true fraction of the operation of the participation

When there is a real score involved, is to a certain extent random, not completely random, need to be improved

Code:

#include <iostream>
using namespace Std;
int main ()
{
int a,b,c,d,e; Define several shaping variables
for (int i=0;i<30;i++)
{
A=1+rand ()%100; Generate random numbers
B=1+rand ()%100;
C=1+rand ()%100;
D=1+rand ()%4;
E=rand ()%2;

if (e==0)//When e=0, it is an integer arithmetic
{
Switch (d)
{
Case 1:
cout<<a<< "+" <<b<< "=" <<endl;
Break
Case 2:
cout<<a<< "-" <<b<< "=" <<endl;
Break
Case 3:
cout<<a<< "*" <<b<< "=" <<endl;
Break
Case 4:
cout<<a<< "/" <<b<< "=" <<endl;
Break
}
}
else (e==1); When E=1, the real score is the arithmetic of participation.
{
if (c>a)

Switch (d)
{
Case 1:
cout<< "(" <<a<< "/" <<c<< ")" << "+" <<b<< "=" <<endl;
Break
Case 2:
cout<< "(" <<a<< "/" <<c<< ")" << "-" <<b<< "=" <<endl;
Break
Case 3:
cout<< "(" <<a<< "/" <<c<< ")" << "*" <<b<< "=" <<endl;
Break
Case 4:
cout<< "(" <<a<< "/" <<c<< ")" << "/" <<b<< "=" <<endl;
Break
}
}
}
return 0;
}

Randomly generate arithmetic questions within 100 of 30-way

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.