### Coin flipping problem

Hello everyone,

I was assigned to write a program that will solve this problem:
--------------------------------------------------------------------------

Write a program that simulates coin tossing. For each toss of the coin the
program should print Heads or Tails. Let the program toss the coin 100 times, and count the number of times each side of the coin appears. Print the results. The program should call a separate function flip()that takes no arguments and returns 0 for tails and 1 for heads.

---------------------------------------------------------------------------

Here's the program I have written so far.
 ``1234567891011121314151617181920212223242526272829303132333435`` ``````#include #include using namespace std; int flip(); int main () { int coin, counter, tails = 0, heads = 0; for (counter = 1; counter <= 100; counter++) { coin = int flip (); if(coin == 0) { cout<<"T "; tails = tails + 1; } else if( coin == 1) { cout<<"H "; heads = heads + 1; } } cout<

I keep getting the error "Error LNK1120: 1 unresolved externals." I don't what that is nor how to fix it. Can anyone tell me where I went wrong? Thank you!
Hi there!
at line 12, you don't have to write the type of the function, omit the '`int`' and that should do it.
Last edited on
Thank you for the prompt reply, but it still is showing the error after making the change you suggested :(
i tried the above code without the int and it worked for me.

what compiler are you using?
I'm using visual studios 2012 express.
 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````#include #include #include using namespace std; int flip(); int main () { int coin, counter, tails = 0, heads = 0; for (counter = 1; counter <= 100; counter++) { coin = flip (); if(coin == 0) { cout<<"T "; tails = tails + 1; } else if( coin == 1) { cout<<"H "; heads = heads + 1; } } cout<

This is u're code with minor change. You should include the conio.h so u can have access to the _getch() to stop the program.
And if u don't want the numbers to be the same each time, u should put a srand(time(NULL)); before the for. So it can generate new numbers every time
Last edited on
Topic archived. No new replies allowed.