源代码:
#include<stdio.h>//c
#include<iostream>//c++
#include<stdlib.h>//标准库文件
#include<float.h> //浮点数处理
#include<fstream>//居中输出控制
#include<iomanip>//居中控制头文件
using namespace std;//命名空间
int main(void)//主函数
{
ch:
float f;//定义小数变量
int a, i, q, w, h, input, b, k, c = 0, z = 0;//定义整数变量
system("cls");//清屏
system("@echo off");//关闭系统输出
cout << "----------------------------------------" << endl;
cout << setw(15) << " " << "速算王者" << endl;//控制居中
system("echo 你好,%username%!");
cout << "请输入最大值:";//最大值确定
cin >> a;//输入
cout << "请输入题量:";//题量控制
cin >> b;//输入
system("cls");//清屏
cout << setw(15) << " " << "速算王者" << endl;//居中控制
cout << "----------------------------------------" << endl;
//printf("%d\n", rand());
for (i = 1; i <= b; i++)
{
q = rand() % (a - 0 + 1) + 0;//取随机数 1
w = rand() % (a - 0 + 1) + 0;//取随机数 2
h = q + w;
cout << q << "+" << w << "=";//输出题目
cin >> input;//输入
if (input == h)//判断正误
{
cout << "回答正确\n";//正
z++;//正确+1
cout << "----------------------------------------\n";
}
else
{
cout << "回答错误\n";//误
c++;//错误+1
cout << "----------------------------------------" << endl;
}
}
cout << "错误" << c << "题\n";//统计错题
cout << "正确" << z << "题\n"; //统计正确题
cout << "共" << b << "题\n";
if (b == z)//满分
{
cout << "100分" << endl;//输出
}
else//计算总分
{
f = static_cast<float>(100) / b * z;//分数计算
cout << f << "分" << endl;//分数输出
}
cout << "----------------------------------------" << endl;
cout << "想重来一遍吗(想1,不想2)" << endl;//询问
cin >> k;//输入
if (k == 1)//想
{
goto ch;//重来
}
else//不想
{
goto exit;//结束
}
exit:
system("pause");//按任意键
return 0;//返回值0
}
我想在中间插入一个倒计时,用了#include<window.h>的sleep,可必须在前台等待,整个代码块都会等待,有没有办法在后台倒计时?