Need quick help on rand()!


so basically T is two dollar and H is also Two dollar but ends coinflip.


This is what my professor expect to see if he runs it.
TTTH You win $16.00
TH You win $4.00
TH You win $4.00
H You win $2.00
TTTTH You win $32.00
TH You win $4.00
H You win $2.00
H You win $2.00
TH You win $4.00
TH You win $4.00
The average payout was $7.40


This is what I wrote and nothing is display
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int main()
{ srand(time(0));
int i;
bool out= true;
double money = 0, total = 0, average;

for (i = 1; i <= 10; i++)
{
int coinflip = rand() * 2 + 1;
do
{
if (coinflip == 1)
{
cout << "T";
money = 2.00;
total *= money;
}
if (coinflip == 2)
{
cout << "H" << endl;
total * 2;
if (total = 0)
total = 2.00;
out = false;
}
} while (out);
cout << "You win $ " << total;
}
average = total / 10;
cout << "The average payout was $" << average << endl;

return 0;
}
Use code tags. You have
int coinflip = rand() * 2 + 1;
which should be
int coinflip = rand() % 2 + 1
i am an idot thx you so much !
Last edited on
Topic archived. No new replies allowed.