질문 : 더블 압연까지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가 같은 경우에도 프로그램은 멈추지 않습니다.