1)I have to include
#include <cstdlib> // for srand
to define the srand() symbol.
2) There is no reason for all of this:
random_integer = rand() % (HIGH - LOW + 1) + LOW;
Since you just want a number from 0 to 1, you can just use rand()
3)Your main problem is that you are trying to compare 'h' or 't' to 0 or 1! This will not work!
Below is how I would do it. I just set a char coin variable based on the int variable that you generate. Then I compare the char guess with the char coin.
#include <iostream>
#include <ctime>
#include <cstdlib> // for srand
using namespace std;
int main ()
{
char guess;
char ans;
int no_of_plays;
const int LOW = 0; //It will auto range the output to within H and T
const int HIGH = 1;
int random_integer;
cout << "THE GAME OF HEAD OR TAILS" << endl;
cout << "" << endl;
cout << "Do you want to play? " << endl;
cout << "Y/y for yes, N/n for no " << endl;
cin >> ans;
if (ans == 'y' || ans == 'Y') {
cout << "How many times do you want to play? " << endl;
cin >> no_of_plays;
}
else {
cout << "Thanks for playing! " << endl;
}
for ( int a = 0; a < no_of_plays; a++)
{
cout << "Call it, Heads or Tails?" << endl;
cout << …