コイントスのループを実行するプログラムを作成する必要があります。コンソールに数字を入力して、その数だけコイントスのループを実行させることがサポートされています。ネストされたループを使用する必要があります。私はこれに何時間も取り組んできましたが、うまくいきません。
コンソールの I/O は次のようになります:
Enter the number of tosses to perform [0=exit]: 3 Heads Tails Heads
実行するトスの数を入力してください [0=終了]: 2 テール テール
実行するトスの数を入力してください [0=終了]: 0
これは私がこれまで持っているコードです:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main ()
{
srand(time(0));rand();
int result = rand() % 2;
while (true)
{
int n; // this many tosses
cout << "How many tosses";
cin >> n;
cin.ignore (1000, 10);
if (n == 0)
break;
for (int i = 0; i < n; i++)
//random number generator
{
if (result == 0)
cout<< "Heads"<<endl;
else if (result == 1)
cout << "Tails"<<endl;
else if (result != 0 || result !=1)
return 0;
} //for
}//while
}//main