質問:
ダブルが出るまで、3 つのサイコロを繰り返し振ります (いずれか 2 つが同じ)。毎回値を表示し、その後、ダブルを取得するのにかかった試行回数を示します。
私のコード:
#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 が同じ場合でも、プログラムは停止しません。