搜索
查看: 715|回复: 5
打印 上一主题 下一主题

这。。。。。。

[复制链接]
跳转到指定楼层
楼主
发表于 2014-2-26 20:54:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5啊哈币
#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--)
{
  srand()((unsigned)time(NULL));
  a=rand()()%50;
  srand()((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怎么编泽失败。

最佳答案

查看完整内容

啊哈C只能用于编译C语言程序,以上代码是C++代码 如果要编译它的话,可以使用g++(内核)+Code::Blocks(IDE) 下载安装请至 http://sourceforge.net/projects/codeblocks/files/Binaries/13.12/Windows/codeblocks-13.12mingw-setup.exe/download 同时下载安装Code:: Blocks和mingw32(Windows下的G++,G++原本是为UNIX开发的) 当然,由于是外国软件,所以是英文版 不过有汉化的方法,去网上搜一下, 最新版的汉化 ...

评分

参与人数 1啊哈币 +3 收起 理由
李掌柜 + 3 你这段C++代码很有意思~~

查看全部评分

沙发
发表于 2014-2-26 20:54:05 | 只看该作者
啊哈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:12 | 只看该作者
  1. //是不是少了个头文件,,试试我给你修改了的代码~~
  2. //这是C++语言吧~
  3. #include<iostream>
  4. #include<cstdlib>
  5. #include<ctime>
  6. using namespace std;
  7. int score=0;
  8. void jisuan(int a,int b)
  9. {
  10. int count=1,sum,t,n;

  11. if((a+b)%2==0)
  12. { n=3;
  13.   sum=a+b;
  14.   cout<<"请计算:"<<a<<"+"<<b<<"=";
  15.   while(n--)
  16.   {
  17.   cin>>t;
  18.   if(t==sum)
  19.    {if(count==1)
  20.    score+=10;
  21.    if(count==2)
  22.    score+=7;
  23.    if(count==3)
  24.    score+=5;
  25.    return ;
  26.    }
  27.   else
  28.   {  if(count!=3)
  29.    cout<<"您的答案好像不对哦,请重新输入:";
  30.    else
  31.     { cout<<"您已经错了三次.."<<endl;
  32.   cout<<"正确答案是:"<<sum<<endl;
  33.     return ;
  34.     }
  35.    count++;
  36.   }
  37.   }
  38. }
  39. else
  40. { n=3;
  41.   if(a<b)
  42.   { t=a;
  43.    a=b;
  44.    b=t;
  45.   }
  46.   sum=a-b;
  47.   cout<<"请计算:"<<a<<"-"<<b<<"=";
  48.   while(n--)
  49.   { cin>>t;
  50.   if(t==sum)
  51.    {if(count==1)
  52.    score+=10;
  53.    if(count==2)
  54.    score+=7;
  55.    if(count==3)
  56.    score+=5;
  57.    return ;
  58.    }
  59.   else
  60.   { if(count!=3)
  61.    cout<<"您的答案好像不对哦,请重新输入:";
  62.    else
  63.     { cout<<"您已经错了三次.."<<endl;
  64. cout<<"正确答案是:"<<sum<<endl;
  65.     return ;
  66.     }
  67.     count++;
  68.   }
  69.   
  70.   }
  71. }

  72. }
  73. int main()
  74. { int n=10;
  75. int a,b,i,j,sum;
  76. while(n--)
  77. {
  78.   srand(unsigned(time(0)));
  79.   a=rand()%50;
  80.   srand(unsigned(time(0)));
  81.   b=rand()%49;
  82.   while(1)
  83.   {
  84.   if(a+b<50)
  85.    break;
  86.   if(a>0)
  87.   a--;
  88.   if(b>0)
  89.   b--;
  90.   }
  91.   jisuan(a,b);
  92.   
  93. }
  94. cout<<"您的成绩为:"<<score<<endl;
  95. if(score>=90)
  96.   cout<<"******************SMART******************";
  97. else if(score>=80&&score<90)
  98.   cout<<"******************GOOD******************";
  99. else if(score>=70&&score<80)
  100.   cout<<"*******************OK*******************";
  101. else if(score>=60&&score<70)
  102.   cout<<"******************PASS******************";
  103. else if(score>=60&&score<70)
  104.   cout<<"************TRY AGAIN**************";
  105. return 0;
  106. }
复制代码
地板
发表于 2014-2-27 23:00:07 | 只看该作者
ahaC是C编译器,你用来编译c++当然不行
5#
发表于 2014-2-27 23:18:44 | 只看该作者
。。。。。汗
6#
发表于 2014-2-28 18:04:01 | 只看该作者
你的代码也有问题,
rand、srand声明在stdlib.h(C语言)或cstdlib(C++)中,你需要#include <cstdlib>
而且:
  1. srand()((unsigned)time(NULL));
  2.   a=rand()()%50;
  3.   srand()((unsigned)time(NULL));
复制代码

这几句都多了对()
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表