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 heads = 0;
int tails = 0;
int coin;
srand (time(0));
for (int flip = 1; flip <= 10; flip++) {
coin = 1 +rand()%2;
switch (coin) {
case 1:
++heads;
break;
case 2:
++tails;
break;
default:
cout <<"?";
}
}
calculateTotal (heads,tails);
cout <<"Heads was flipped "<<heads<<" times"<<endl;
cout <<"Tails was flipped "<<tails<<" times\n"<<endl;
return 0;
}
int calculateTotal (int head,int tail)
{
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;
}