啊哈磊_编程从这里起步
标题:
这。。。。。。
[打印本页]
作者:
ahz13426772395
时间:
2014-2-26 20:54
标题:
这。。。。。。
#include<iostream>
#include<ctime>
using namespace std
;
int score=0;
void jisuan(int a,int b)
{
int count=1,sum,t,n;
if((a+b)%2==0)
{ n=3;
sum=a+b;
cout<<"请计算:"<<a<<"+"<<b<<"=";
while(n--)
{
cin>>t;
if(t==sum)
{if(count==1)
score+=10;
if(count==2)
score+=7;
if(count==3)
score+=5;
return ;
}
else
{ if(count!=3)
cout<<"您的答案好像不对哦,请重新输入:";
else
{ cout<<"您已经错了三次.."<<endl;
cout<<"正确答案是:"<<sum<<endl;
return ;
}
count++;
}
}
}
else
{ n=3;
if(a<b)
{ t=a;
a=b;
b=t;
}
sum=a-b;
cout<<"请计算:"<<a<<"-"<<b<<"=";
while(n--)
{ cin>>t;
if(t==sum)
{if(count==1)
score+=10;
if(count==2)
score+=7;
if(count==3)
score+=5;
return ;
}
else
{ if(count!=3)
cout<<"您的答案好像不对哦,请重新输入:";
else
{ cout<<"您已经错了三次.."<<endl;
cout<<"正确答案是:"<<sum<<endl;
return ;
}
count++;
}
}
}
}
int main()
{ int n=10;
int a,b,i,j,sum;
while(n--)
{
s
rand()
((unsigned)time(NULL));
a=
rand()
()%50;
s
rand()
((unsigned)time(NULL));
b=rand()%49;
while(1)
{
if(a+b<50)
break;
if(a>0)
a--;
if(b>0)
b--;
}
jisuan(a,b);
}
cout<<"您的成绩为:"<<score<<endl;
if(score>=90)
cout<<"******************SMART******************";
else if(score>=80&&score<90)
cout<<"******************GOOD******************";
else if(score>=70&&score<80)
cout<<"*******************OK*******************";
else if(score>=60&&score<70)
cout<<"******************PASS******************";
else if(score>=60&&score<70)
cout<<"************TRY AGAIN**************";
return 0;
}这个不行吗?啊哈c怎么编泽失败。
作者:
981013
时间:
2014-2-26 20:54
啊哈C只能用于编译C语言程序,以上代码是C++代码
如果要编译它的话,可以使用g++(内核)+Code::Blocks(IDE)
下载安装请至
http://sourceforge.net/projects/ ... -setup.exe/download
同时下载安装Code:: Blocks和mingw32(Windows下的G++,G++原本是为UNIX开发的)
当然,由于是外国软件,所以是英文版
不过有汉化的方法,去网上搜一下,
最新版的汉化包可能还没出,旧版的也可以用在最新版上。
作者:
李掌柜
时间:
2014-2-27 22:58
//是不是少了个头文件,,试试我给你修改了的代码~~
//这是C++语言吧~
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int score=0;
void jisuan(int a,int b)
{
int count=1,sum,t,n;
if((a+b)%2==0)
{ n=3;
sum=a+b;
cout<<"请计算:"<<a<<"+"<<b<<"=";
while(n--)
{
cin>>t;
if(t==sum)
{if(count==1)
score+=10;
if(count==2)
score+=7;
if(count==3)
score+=5;
return ;
}
else
{ if(count!=3)
cout<<"您的答案好像不对哦,请重新输入:";
else
{ cout<<"您已经错了三次.."<<endl;
cout<<"正确答案是:"<<sum<<endl;
return ;
}
count++;
}
}
}
else
{ n=3;
if(a<b)
{ t=a;
a=b;
b=t;
}
sum=a-b;
cout<<"请计算:"<<a<<"-"<<b<<"=";
while(n--)
{ cin>>t;
if(t==sum)
{if(count==1)
score+=10;
if(count==2)
score+=7;
if(count==3)
score+=5;
return ;
}
else
{ if(count!=3)
cout<<"您的答案好像不对哦,请重新输入:";
else
{ cout<<"您已经错了三次.."<<endl;
cout<<"正确答案是:"<<sum<<endl;
return ;
}
count++;
}
}
}
}
int main()
{ int n=10;
int a,b,i,j,sum;
while(n--)
{
srand(unsigned(time(0)));
a=rand()%50;
srand(unsigned(time(0)));
b=rand()%49;
while(1)
{
if(a+b<50)
break;
if(a>0)
a--;
if(b>0)
b--;
}
jisuan(a,b);
}
cout<<"您的成绩为:"<<score<<endl;
if(score>=90)
cout<<"******************SMART******************";
else if(score>=80&&score<90)
cout<<"******************GOOD******************";
else if(score>=70&&score<80)
cout<<"*******************OK*******************";
else if(score>=60&&score<70)
cout<<"******************PASS******************";
else if(score>=60&&score<70)
cout<<"************TRY AGAIN**************";
return 0;
}
复制代码
作者:
rosynirvana
时间:
2014-2-27 23:00
ahaC是C编译器,你用来编译c++当然不行
作者:
超神级
时间:
2014-2-27 23:18
。。。。。汗
作者:
981013
时间:
2014-2-28 18:04
你的代码也有问题,
rand、srand声明在stdlib.h(C语言)或cstdlib(C++)中,你需要#include <cstdlib>
而且:
srand()((unsigned)time(NULL));
a=rand()()%50;
srand()((unsigned)time(NULL));
复制代码
这几句都多了对()
欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/)
Powered by Discuz! X3.2