問題:C++程序骰子難點
反覆輥3個骰子直到雙打被卷(任何兩個是 相同)。每次顯示值和之後說明有多少嘗試 它獲得雙打。
我的代碼:
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main()
{
srand (time(NULL));
int j=1;
int i=0;
int a;
int b;
do
{
int a=(rand()%6+1);
int b=(rand()%6+1);
cout<<a<<" and "<<b<<endl<<endl;
j++;
}
while (a!=b);
cout<<"They are the same!"<<endl<<endl;
cout<<"It took "<<j<<" tries.";
return 0;
}
問題:
循環將不會停止。即使a和b相同,程序也不會停止。