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;
}

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.

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 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;
}

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.