Arithmetic 1
First, design ideas:
1. The main part of the program is the loop output, the number of topics by the user input;
2. Three integer variable +rand function to implement the random number arithmetic, one variable represents subtraction, and the other two are used as operands;
3. User experience: The topic is divided into three columns, neat and tidy spacing, and will not show a divisor of 0.
Second, the source code
Arithmetic. Cpp:defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
#include "Stdlib.h"
#include "time.h"
int main (int argc, char* argv[])
{
int a,b,c,n=1; A represents the operation symbol, b c is two numbers, n indicates the number of the question.
Srand ((unsigned) time (NULL)); The Srand () function produces a random seed that starts at the current time
cout<< "Please enter the number of question:";
cin>>n;
for (int i=1;i<=n;i++)
{
A=rand ()%4;
B=rand ()%100; b c is a two random integer within 100
C=rand ()%100;
cout<< "(" <<i<< ")" <<b;
Switch (a)
{
Case 1:cout<< "+" <<c<< "=\t\t";
Case 2:cout<< "-" <<c<< "=\t\t";
Case 3:cout<< "*" <<c<< "=\t\t";
Case 0:if (c==0) {i--;break;}
cout<< "/" <<c<< "=\t\t";
default:cout<< "+" <<c<< "=\t\t";
}
if (i%3==0)
cout<<endl;
}
cout<<endl;
return 0;
}
Iii. Results of operation
Iv. difficulties encountered
Since a winter vacation did not touch the programming, the biggest difficulty for me is not knowing the usage of the RAND function and the header file where it resides. After drawing on the program of Bin等, the basic function was soon realized. After that, I adjusted the page again. Added Srand ((unsigned) time (NULL)); 。 Because only the RAND function is used, the random number generated by each run of the program computer is fixed.
Individual Job 3:4 Operation one