Today in class let us do a arithmetic program, although it is a simple topic, but I do not move the head of the really did not do it, but the positive brain, think of a lot of ways, finally I thought I was also able to program, the first time let me feel a little ability, although insignificant, But this insignificant confidence has made me change myself.
Ideas:
First, I first construct a C framework;
Then, the problem that needs to be solved is two random numbers and random four;
Then, according to the requirements of the loop to write 30 operational questions;
The last is debug run.
Program:
#include <iostream.h>
#include <stdlib.h>
int main ()
{
cout<< "Please do 30 contact questions. "<<endl;
int i,x,y,n,a;
for (i=1;i<31;i++)
{
X=rand ()%100;
Y=rand ()%100;
A=rand ();
n=a%4;
Switch (n)
{
Case 0:cout<<x<< "+" <<y<< "=" <<endl;break;
Case 1:cout<<x<< "-" <<y<< "=" <<endl;break;
Case 2:cout<<x<< "*" <<y<< "=" <<endl;break;
Case 3:cout<<x<< "/" <<y<< "=" <<endl;break;
}
}
return 0;
A bit is run:
}
Our first lesson in software engineering