C++扬帆远航——9(小学生算数程序)

来源:互联网 发布:python 指数函数 编辑:程序博客网 时间:2024/04/30 06:24
/* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:studentjishu.cpp * 作者:常轩   * 微信公众号:Worldhello * 完成日期:2016年3月16日 * 版本号:V1.0 * * 问题描述:程序随机输出100以内的加减乘除算式,然后做题人输入答案,计算机给出结果,最后统计得分。 * 程序输入:算式结果 * 程序输出:见运行结果 */ #include<iostream>using namespace std;#include<ctime>#include<cstdlib>int main(){    void chuti();chuti();return 0;}void chuti(){int a,b,t;char l;int c;int i;int q;    int score=0;for(i=1;i<=10;i++){           srand(time(0));a=rand()%100+1;        b=rand()%100+1;        cout<<"第"<<i<<"题:"<<endl;    int t;    LOOP:    t=rand()%4+1;    int  m;switch(t){case 1:m=a+b;            cout<<a<<"+"<<b<<"=";break;case 2:if(a<b){q=a;a=b;b=q;}m=a-b;            cout<<a<<"-"<<b<<"=";break;case 3:            m=a*b;            cout<<a<<"x"<<b<<"=";break;default:if(a%b==0)                     {m=a/b;               cout<<a<<"/"<<b<<"=";}elsegoto LOOP;}cin>>c;if(m==c){cout<<"right!"<<endl;score=score+10;}else            cout<<"wrong!"<<endl;}cout<<"共答对了"<<score/10<<"道题,得分"<<score<<endl;}运行结果:
<img src="http://img.blog.csdn.net/20160323174443521?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
总结:
    程序中唯一不足,就是除法算式出现的几率太小,以后会在改正的

0 0