# C++高手幫debug

#include<iostream>

#include <time.h>

#include <stdlib.h>

using namespace std;

int main()

{ int i,n1,n2,N,S=1,R,Guess;

srand(time(NULL));

R=1+rand()%12;

while(S=1)

{

srand(time(NULL));

cout << R << endl;//跑出亂數值給玩家猜

cout <<"猜大請按1猜小請按0"<<endl;//選擇紐

cin >> Guess;

n1=1+rand()%6;

n2=1+rand()%6;

N=n1+n2;

cout << n1 << endl;

cout << n2 << endl;

if((Guess==1)&&(N>=7))//猜大成功

{

cout<<"恭喜達對"<<endl;

R=N;

}

else

if((Guess==0)&&(N<=7))//猜小成功

{

cout<<"恭喜達對"<<endl;

R =N;

}

else if((Guess==1)&&(N<7)) //失敗

{

cout<<"失敗! 是否再來過? 是(1)否(0)"endl;

cin>>S;

R=N;

}

else if((Guess==0)&&(N>7))

{

cout<<"失敗! 是否再來過? 是(1)否(0)"endl;

cin>>S;

R=N;

}

}

cout<<"game over"<<endl;//遊戲結束

system("PAUSE");

return 0;

}

### 5 個解答

• 最佳解答

#include <iostream>

#include <time.h>

#include <stdlib.h>

using namespace std;

int main() {

int n1,n2,S,N;

const string O[] = {(const string)"失敗!", (const string)"恭喜達對"};

for( srand(time(NULL)) ,

S = 1 ;

1 == S &&

cout <<"猜大請按1猜小請按0"<<endl &&//選擇紐

cin >> S ;

cout << "是否再來過? 是(1)否(0)" << endl ,

cin >> S ){

cout << (n1=1+rand()%6) << endl;

cout << (n2=1+rand()%6) << endl;

cout << "sum = " << (N=n1+n2) << endl;

cout << O[((S==1)==(N>=7))] << endl;

}

cout<<"game over"<<endl;//遊戲結束

return 0;

}

2014-01-23 21:17:08 補充：

> 卡牌遊戲"UNLIGHT"的獎勵遊戲一樣喔..

FB不讓我玩她耶!

2014-01-23 21:29:40 補充：

恭喜達對 = good match?

Dude, use your imaginations and stop being a scientist.

2014-01-23 21:31:06 補充：

That is why I don't date boys major in sciences. They are soooo boring!

2014-01-24 01:36:21 補充：

Then, you are less than 20 feet away from the yukky boredom...

• Haha, my first impression to the code matches Tai's 004.

And do 006 and 008 constitute any discrimination? =P

• If that were a pun, everybody would like it.

• 恭喜達對 => 恭喜答對

2014-01-23 23:33:01 補充：

A scientist usually has imaginations, and the boring guy is an engineer. I like to be an engineer.

2014-01-28 02:39:16 補充：

It's all right, I know it's a pun.

Happy Chinese New Year to all.

• 您覺得這個回答如何？您可以登入為回答投票。
• 35 跟 41行的 endl前面要加 "<<"