天天看點

國小生算數測試

問題及代碼:

/*copyright(c++).煙台大學計算機與控制工程學院
檔案名稱:預設函數
作者:馬豔豔
完成日期:2016年3月24日
版本号:vc++6.0
問題描述:随機産生一個1000内的數字,要求使用者猜測這個整數。輸入一個猜測想的整數,判斷是否與産生的随機數相同。
輸入描述:輸入一個猜測想的整數。
輸出描述:比對結果;*/
#include <iostream>
#include<cstdlib>
int randing();
using namespace std;
int main()

{
    
    int n,i,t,m=0;
    cin>>n;
	srand(n);
	
    for(i=1;i<=10;i++)
    {
		
        cout<<"第"<<i<<"題"<<endl;
		t=randing();
		m+=t;
       

    }
	 cout<<m<<endl;
	
    
 return 0;
}
int randing()
{
	int h,t,m;
    int s1,s2,sum,p,s,i=0;
    while(1)
    {
		s1=rand()%100;
		s2=rand()%100;
		s=rand()%4;
		  switch(s)
		  {
			case 0:
				cout<<s1<<"+"<<s2<<"=";
				cin>>p;
				if(p==s1+s2)
				{
					cout<<"correct"<<endl;
					i++;
				
				
				}
				
				else
					cout<<"error"<<endl;;
					break;
			case 1:
				cout<<s1<<"*"<<s2<<"=";
				cin>>p;
				if(p==s1*s2)
				{
					cout<<"correct"<<endl;
					i++;
				
				}
			
				else
					cout<<"error"<<endl;;
					break;
			case 2:
				cout<<s1<<"-"<<s2<<"=";
				cin>>p;
					if(p==s1-s2)
				{
					cout<<"correct"<<endl;;
					i++;
					
				}
				
				else
					cout<<"error"<<endl;;
				break;			
			case 3:
				if(s1%s2!=0)
				t=s1%s2;
				m=s1/s2;
				h=m+t;
				cout<<s1<<"/"<<s2<<"=";
				cin>>p;
					if(p==h)
				{
					cout<<"correct"<<endl;;
					i++;
				
				}
				
				else
					cout<<"error"<<endl;break;
			default:
				cout<<"wrong"<<endl;
				break;
		  }
		 
			 return i;
	}
	
}
           
國小生算數測試

知識點總結:

switch語句的應用還有死循環break,整體來說,這個程式很用心思。

學習心得:

感覺收獲很大。沉下心來。