標題:
超級金頭腦 (一)
[打印本頁]
作者:
鄭繼威
時間:
2023-8-22 19:07
標題:
超級金頭腦 (一)
設計遊戲 "超級金頭腦",
讓使用者計算兩個範圍介於51~99之隨機亂數的和.
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x, y, ans, ans_c;
//51~99->-51 ->0~48
x=rand()%49+51;
y=rand()%49+51;
ans_c=x+y; //正確答案
cout<<x<<" + "<<y<<" = ";
long t1,t2,pass;
t1=clock();
cin>>ans; //使用者輸入答案
t2=clock();
pass=t2-t1; //經過的秒數
//判斷使用者輸入的答案是否等於正確答案
if(ans_c==ans)
{
cout<<"答對了! 本題花了"<<pass<<"毫秒思考!"<<endl;
}
else
{
cout<<"答錯了! 本題花了"<<pass<<"毫秒思考!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
邱品惟
時間:
2023-8-22 21:07
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int e=0;
re:
srand(time(NULL));
int a,b,c,d;
a=rand()%49+51;
b=rand()%49+51;
c=a+b;
cout<<a<<"+"<<b<<"=";
long f,g,h;
f=clock();
cin>>d;
g=clock();
h=-(f-g);
if(c==d)
{
cout<<"答對了,這題花了"<<h<<"毫秒"<<endl;
e++;
if(e==2)
goto bye;
goto re;
}
else
{
cout<<"答錯了,這題花了"<<h<<"毫秒"<<endl;
e++;
if(e==2)
goto bye;
goto re;
}
bye:
system("pause");
return 0;
}
複製代碼
作者:
陳宣廷
時間:
2023-8-25 20:37
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int a,b;
int my_ans,ans;
a=rand()%49+51;
b=rand()%49+51;
ans=a+b;
cout<<a<<"+"<<b<<"=";
long start,end,pass;
start=clock();
cin>>my_ans;
end=clock();
pass=end-start;
if(ans==my_ans)
cout<<"答對了! 花了"<<pass<<"毫秒";
else
cout<<"答錯了! 花了"<<pass<<"毫秒";
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡沛倢
時間:
2023-8-25 20:39
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int a,b,c1,c2;
srand(time(NULL));
a=rand()%49+51;
b=rand()%49+51;
c1=a+b;
long d1,d2;
cout<<a<<"+"<<b<<"=";
d1=clock();
cin>>c2;
d2=clock();
if(c1==c2)
{
cout<<"答對了! 你花了"<<clock()<<"毫秒!"<<endl;
}
if(c1!=c2)
{
cout<<"答錯了! 你花了"<<clock()<<"毫秒!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
張絜晰
時間:
2023-8-25 20:40
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
srand(time(NULL));
int x,y,z,ans;
x=rand()%49+51;
y=rand()%49+51;
ans=x+y;
cout<<"What's"<<x<<"+"<<y<<"?"<<endl;
float t,tt, ttt;
t=clock();
cin>>z;
tt=clock();
ttt=tt-t;
if(z==ans){
cout<<"Yessss you got it! ";
}
else{
cout<<"ur dumb... ";
}
cout<<"You took exactly "<<ttt/1000<<" seconds.";
system("pause");
return 0;
}
複製代碼
作者:
黃子豪
時間:
2023-8-25 20:40
#include<iostream>
#include<ctime>
using namespace std;
int main(){
srand(time(NULL));
int a, b, ans, ans_c;
a=rand()%49+51;
b=rand()%49+51;
ans_c=a+b;
cout<<a<<"+"<<b<<"=";
int start, end, pass;
start=clock();
cin>>ans;
end=clock();
pass=end-start;
if(ans_c==ans){
cout<<"答對了! 本題花了"<<pass<<"毫秒思考!\n";
}
else{
cout<<"答錯了! 本題花了"<<pass<<"毫秒思考\n!";
}
system("pause");
return 0;
}
複製代碼
作者:
盧玄皓
時間:
2023-8-25 20:41
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x, y, ans, ans_c;
x=rand()%49+51;
y=rand()%49+51;
ans_c=y+x;
cout<<x<<" + "<<y<<" = ";
long a,b,c;
a=clock();
cin>>ans
b=clock();
c=b-a;
if(ans_c==ans)
{
cout<<"答對,花了"<<c<<"毫秒"<<endl;
}
{
cout<<"答錯了花了"<<c<<"毫!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
何權晉
時間:
2023-8-25 20:41
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x,y,ans,ans_1;
x=rand()%49+51;
y=rand()%49+51;
ans=x+y;
cout<<x<<" + "<<y<<" = ";
int start,end,p;
start=clock();
cin>>ans_1;
end=clock();
p=end-start;
if(ans==ans_1)
{
cout<<"Correct. Time taken: "<<p<<" Seconds"<<endl;
}
else
{
cout<<"Incorrect. Time taken: "<<p<<" Seconds"<<endl;
}
system("pause");
return 0;
system("pause");
return 0;
}
複製代碼
作者:
呂得銓
時間:
2023-8-25 20:43
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x, y, ans, ans_c;
x=rand()%49+51;
y=rand()%49+51;
ans_c=x+y;
cout<<x<<" + "<<y<<" = ";
long t1,t2,pass;
t1=clock();
cin>>ans;
t2=clock();
pass=t2-t1;
if(ans_c==ans)
{
cout<<"答對了! 本題花了"<<pass<<"毫秒思考!"<<endl;
}
else
{
cout<<"答錯了! 本題花了"<<pass<<"毫秒思考!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
廖秝瑜
時間:
2023-8-25 20:43
#include<cstdlib>
#include<ctime>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int a, b, c, d;
a=rand()%49+51;
b=rand()%49+51;
c=a+b;
cout<<a<<" + "<<b<<" = ";
long e,f,g;
e=clock();
cin>>d;
f=clock();
g=f-e;
if(c==d)
{
cout<<"答對共花了"<<g<<"秒"<<endl;
}
else
{
cout<<"答錯共花了"<<g<<"秒"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
李柏漢
時間:
2023-8-25 20:49
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x, y, ans, ans_c;
x=rand()%49+51;
y=rand()%49+51;
ans_c=x+y;
cout<<x<<" + "<<y<<"= ";
long t1,t2,pass;
t1=clock();
cin>>ans;
t2=clock();
pass=t2-t1;
if(ans_c==ans)
{
cout<<"答對了!本題花了"<<pass<<"秒思考!"<<endl;
}
else
{
cout<<"答錯了!本題花了"<<pass<<"秒思考!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
鄭繼威
時間:
2023-8-25 20:53
9
作者:
呂宗晉
時間:
2023-9-2 16:23
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x, y, ans, ans_c;
x=rand()%49+51;
y=rand()%49+51;
ans_c=x+y;
cout<<x<<" + "<<y<<" = ";
long t1,t2,pass;
t1=clock();
cin>>ans;
t2=clock();
pass=t2-t1;
if(ans_c==ans)
{
cout<<"答對了! 本題花了"<<pass<<"毫秒思考!"<<endl;
}
else
{
cout<<"答錯了! 本題花了"<<pass<<"毫秒思考!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
呂宗晉
時間:
2023-9-6 21:14
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x, y, ans, ans_c;
long t1,t2,pass;
while(true)
{
x=rand()%49+51;
y=rand()%49+51;
ans_c=x+y;
cout<<x<<" + "<<y<<" = ";
t1=clock();
cin>>ans;
t2=clock();
pass=t2-t1;
if(ans==ans_c)
cout<<"答對了! 本題花了"<<pass<<"毫秒思考!"<<endl;
else
cout<<"答錯了! 本題花了"<<pass<<"毫秒思考!"<<endl;
cout<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
朱奕祈
時間:
2024-4-16 20:45
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int x, y, ans, ans_c;
y=rand()%49+51;
ans_c=x+y;
cout<<x<<" + "<<y<<" = ";
long t1,t2,pass;
t1=clock();
cin>>ans;
t2=clock();
pass=t2-t1;
if(ans_c==ans)
{
cout<<"答對了! 本題花了"<<pass<<"毫秒思考!"<<endl;
}
else
{
cout<<"答錯了! 本題花了"<<pass<<"毫秒思考!"<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2