二柱子
作業要求:1、實現線上答題。
2、答題結束後,可以判斷對錯。
3、並將錯題的結果儲存起來。
程式碼
#include<iostream>
#include<stdarg.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
using namespace std;
int main()
{
cout<<endl;
cout<<"歡迎使用四則運算小程式"<<endl;
cout<<endl;
cout<<endl;
Again:
double Q1=1;
int Q01;
int Q2=1;
int Q3=100;
char Q4='y';
int Q5=1;
char Q6='n';
char Q7='n';
double ans=0;
int right=0;
cout<<" 一.請輸入題目數量:";
cin>>Q1;
Q01=floor(Q1);
// cout<<"請輸入每行列印題目數(1-5):";
// cin>>Q2;
cout<<" 二.行間距(正整數):";
cin>>Q5;
cout<<" 三.請輸入算式中數值的最大值:";
cin>>Q3;
while(1)
{
cout<<" 四.運算中需要乘除法嗎?需要:y;不需要:n";
cin>>Q4;
cout<<" 五.減法中需要有負數嗎?需要y:;不需要:n";
cin>>Q7;
cout<<"`````````````````````````````````````````````````````````````````````````"<<endl;
cout<<"開始答題:"<<endl;
srand(time(NULL));
if(Q4=='y')
{
while(1)
{
if(Q1<1)
{
cout<<"輸入有誤,請重新輸入題目數量:";
cin>>Q1;
Q01=floor(Q1);
}
else
{
for(int j=0;j<Q01;j++)
{
if(j!=0&&j%Q2==0)
{
for(int i=0;i<Q5;i++)
{
cout<<endl;
}
}
int num1=rand()%Q3;
int num2=rand()%Q3;
int sign=rand()%4;
switch(sign)
{
case 0:
cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1+num2)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num1+num2<<endl;
}
break;
case 1:
if(Q7=='y')
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num1-num2<<endl;
}
}
else
{
if(num1>num2)
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num1-num2<<endl;
}
}
else
{
cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<"\t";
cin>>ans;
if(ans==num2-num1)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num2-num1<<endl;
}
}
}
break;
case 2:
cout<<j+1<<":"<<" "<<num1<<"*"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1*num2)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num1*num2<<endl;
}
break;
case 3:
if(num2!=0)
{
cout<<j+1<<":"<<" "<<num1<<"/"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1/num2)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num1/num2<<endl;
}
}
else
{
j--;
}
break;
}
}
break;
}
}
cout<<"共答對"<<right<<"道題;"<<"答錯"<<Q01-right<<"道題。";
cout<<"繼續努力!"<<endl;
break;
}
if(Q4=='n')
{
while(1)
{
if(Q01<1)
{
cout<<"輸入有誤,請重新輸入題目數量:";
cin>>Q1;
Q01=floor(Q1);
}
else
{
for(int j=0;j<Q01;j++)
{
if(j!=0&&j%Q2==0)
{
for(int i=0;i<=Q5;i++)
{
cout<<endl;
}
}
int num1=rand()%Q3;
int num2=rand()%Q3;
int sign=rand()%2;
switch(sign)
{
case 0:
cout<<j+1<<":"<<" "<<num1<<"+"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1+num2)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num1+num2<<endl;
}
break;
case 1:
if(Q7=='y')
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num1-num2<<endl;
}
break;
}
else
{
if(num1>num2)
{
cout<<j+1<<":"<<" "<<num1<<"-"<<num2<<"="<<"\t";
cin>>ans;
if(ans==num1-num2)
{
cout<<"正確"<<endl;
right++;
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num1-num2<<endl;
}
break;
}
else
{
cout<<j+1<<":"<<" "<<num2<<"-"<<num1<<"="<<"\t";
cin>>ans;
if(ans==num2-num1)
{
cout<<"正確";
}
else
{
cout<<"答錯了!"<<endl;
cout<<"正確答案是:"<<num2-num1<<endl;
}
break;
}
}
break;
}
}
}
break;
}
cout<<"共答對"<<right<<"道題;"<<"答錯"<<Q01-right<<"道題。"<<endl;
cout<<"繼續努力!"<<endl;
break;
}
else
{
cout<<"輸入有誤,請按要求輸入!"<<endl;
}
}
cout<<endl;
while(1)
{
cout<<"還需要繼續出題還是退出?(y:繼續出題;n:退出)";
cin>>Q6;
if(Q6=='y')
{
goto Again;
}
if(Q6=='n')
{
goto Exit;
}
else
{
cout<<"輸入有誤,請重新輸入:";
}
}
Exit:
return 0;
}
心得,太困難,一點頭緒沒有!從網上搜索的程式碼,然後加以學習,認識。
一定在C語言上,更加的努力學習