當前位置:編程學習大全網 - 源碼下載 - 小學數學隨機出題C++源代碼

小學數學隨機出題C++源代碼

給,已經編譯運行確認:

#include<iostream>

#include<cstdlib>

using namespace std;

void fuhao(int x)

{

if(x==0) printf("+");

if(x==1) printf("-");

if(x==2) printf("*");

}

int main()

{

int a,b,t,p,flag;

int score=0;

int n,i;

loop :

system("cls");

cout<<"您要答多少題?"<<endl;

cin>>n;

cout<<"開始進入測試!"<<endl;

for(i=0;i<n;i++)

{

cout<<"第"<<i+1<<"題:"<<endl;

a=rand()%10;

b=rand()%10;

if(a<b)

flag=rand()%3;

cout<<a;

fuhao(flag);

cout<<b<<" = ";

cin>>t;

if(flag==0)

{

if(t==a+b)

else cout<<"答錯了!正確答案是: "<<a+b<<endl;

}

if(flag==1)

{

if(t==a-b)

else cout<<"答錯了!正確答案是: "<<a-b<<endl;

}

if(flag==2)

{

if(t==a*b)

else cout<<"答錯了!正確答案是: "<<a*b<<endl;

}

}

cout<<"做對題目的總個數為: "<<score<<endl;

cout<<"是否繼續?1.繼續2.退出"<<endl;

cin>>t;

if(t==1)goto loop;

else cout<<"歡迎使用!再見!"<<endl;

system("pause");

return 1;

}

  • 上一篇:站點間源代碼1001站點間源代碼
  • 下一篇:什麽是EA(智能交易系統)?
  • copyright 2024編程學習大全網