Hey i need help with my program, I need to flip a coin and check how many heads and tails has been flipped. Heads = Win and Tails = Lose. What im trying to do is how do i calculate the winning totals for example what i want is Heads * 2 (ie : 3 heads has been flipped (3 * 2) and 1 tails (-1) (6 - 1 = 5 ) ) i want to be able to make it so that it can times heads by 2 and then subtract how many tails has been flipped but what i get is (ie : 3 - 1 = 2) i dont want that thanks.

``````#include <iostream>
using namespace::std;

#include <iomanip>
using std::setprecision;

#include <cstdlib>

#include <ctime>

int calculateTotal (int,int);

int main()
{
int tails = 0;
int coin;

srand (time(0));

for (int flip = 1; flip <= 10; flip++) {
coin = 1 +rand()%2;

switch (coin) {
case 1:
break;

case 2:
++tails;
break;

default:
cout <<"?";
}
}
cout <<"Tails was flipped "<<tails<<" times\n"<<endl;

return 0;
}
{

int won = head * 2;

int lost = tail;

int money = head - tail;

if (money > 0)
cout<<"Congratulations you won \$"<<money<<endl;
else if (money < 0)
cout <<"Sorry you lost"<<endl;

return money;
}
``````

Edited by Nick Evan: Fixed formatting

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Clinton Portis

I'll make a deal with you.. put code tags around your code, and I will solve your problem for you.

I'll even take out the math.. which is the most complex I have seen for a coin flippin' game.

Edited by Clinton Portis: oy vey!

how do i put code tags? im new to this lol

``````#include <iostream>
using namespace::std;

#include <iomanip>
using std::setprecision;

#include <cstdlib>

#include <ctime>

int calculateTotal (int,int);

int main()
{
int tails = 0;
int coin;

srand (time(0));

for (int flip = 1; flip <= 10; flip++) {
coin = 1 +rand()%2;

switch (coin) {
case 1:
break;

case 2:
++tails;
break;

default:
cout <<"?";
}
}
cout <<"Tails was flipped "<<tails<<" times\n"<<endl;

return 0;
}
{

int won = head * 2;

int lost = tail;

int money = head - tail;

if (money > 0)
cout<<"Congratulations you won \$"<<money<<endl;
else if (money < 0)
cout <<"Sorry you lost"<<endl;

return money;
}``````

You have ye'self a good workin' program up there.. just had to make 2 minor changes:

``````//this
coin = 1 +rand()%2;
//should be this:
coin = 1 +rand()%3;

//this
int money = head - tail;
//should be this:
int money = won - tail;``````
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.