I have to write a program that runs a loop for a coin toss. I am supported to enter a number into the console and have it run a loop of the coin toss for that many times. I need to use nested loops. I have been working on this for hours and cannot make it work.
The console i/o is supposed to look like below:
Enter the number of tosses to perform [0=exit]: 3
Heads
Tails
Heads
Enter the number of tosses to perform [0=exit]: 2 Tails Tails
Enter the number of tosses to perform [0=exit]: 0
This is the code i have so far:
#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