New arithmetic topics C + +

Source: Internet
Author: User

Source:

#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <time.h>
int main ()
{
int a = 0;
int b = 0;
int mode = 0;//0: plus 1: minus 2: Multiply by 3: except
int i = 0;
int c[5]={0,30,1,100,1};//whether to customize, the number of question, whether there is multiplication, the upper limit, the lower value.
Srand ((unsigned) time (NULL)); Initializes the random number generator so that the random number generated for each run is different
printf ("Are you customizing? is input 1, no input 0: ");
cin>>c[0];
if (c[0]==0)
{
for (i=0;i<30;i++)//Do 30 questions
{
A = rand ()% 100; Generates a random number between 0~99
b = rand ()% 100; Generates a random number between 0~99
mode = rand ()% 4; Generates a random number between 0~3, which represents the operator
printf ("%d", a); Print calculation
switch (mode)//OK operator
{
Case 0:
printf ("+%d = \ n", b);
Break
Case 1:
printf ("-%d = \ n", b);
Break
Case 2:
printf ("*%d = \ n", b);
Break
Case 3:
printf ("/%d = \ n", b);
Break
Default
printf ("Somethingis wrong!\n");
Break
}
}
}
else {
cout<< "Please enter the number of question:";
cin>>c[1];
cout<< "Does it contain multiplication? is input 1, no input 0: ";
cin>>c[2];
cout<< "Value upper limit:";
cin>>c[3];
cout<< "Lower value:";
cin>>c[4];
for (i=0;i<c[1];i++)//Custom problem number
{
A = rand ()% (c[3]-c[4]+1) +c[4]; Generate a qualified random number
b = rand ()% (c[3]-c[4]+1) +c[4]; Generate a qualified random number
if (c[2]==1) {
mode = rand ()% 4; Generates a random number between 0~3, which represents the operator
printf ("%d", a); Print calculation
switch (mode)//OK operator
{
Case 0:
printf ("+%d = \ n", b);
Break
Case 1:
printf ("-%d = \ n", b);
Break
Case 2:
printf ("*%d = \ n", b);
Break
Case 3:
printf ("/%d = \ n", b);
Break
Default
printf ("Somethingis wrong!\n");
Break
}
}
else{
mode = rand ()% 2; Generates a random number between 0~3, which represents the operator
printf ("%d", a); Print calculation
switch (mode)//OK operator
{
Case 0:
printf ("+%d = \ n", b);
Break
Case 1:
printf ("-%d = \ n", b);
Break
Default
printf ("Somethingis wrong!\n");
Break
}

}
}

}

return 0;

}

Run:

New arithmetic topics C + +

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.