Yes, this is homework, but I am trying. The problem is:
Simulate coin tossing
Program must print Heads or Tails. Toss 100 times and count the number of times each side of the coin appears. Call a function "flip" that takes no arguments and returns 0 for tails and 1 for heads.
I know I have to use random, I think I have the logic for the function correct. What I'm trying to accomplish is flip the coin, if the coin is 0 then inclement the counter for tails, or if its not 0 inclement the heads counter and cout the appropriate response. My int Main is basically all messed up because based on the examples in my text book it appears that I should have my cout statements in main, but they are also in the function on some examples. Some of the commented out lines are my attempt to debug this thing. I spent four hours getting to this point and I'm not sure where to go. I don't want to just google the answer, I really want to learn this, which is difficult for a 43 y/o system admin trying to increase his knowledge base. C++ seems really neat and I look forward to getting a better understanding of it all. I seem to remember doing these problems when I took Java back in 1998, but, its a perishable skill apparently!!
Regards
Richard
// Chapter3_3_34.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using std::cin;
using std::endl;
using namespace std;
int flip(void);
int main();
//start random generator
// srand( time( 0 ) );
// result = flip;
//start defenition of flip function
int flip( void )
{
int heads = 1; //count the heads result of the flip
int tails = 0; //count the tails result of the flip
int headsCounter = 0; //start the counter at 0
int tailsCounter = 0; //start the counter at 0
int flip; //the coin toss
flip = rand() % 2; //flip the coin
if flip == 1
headsCouter++;
else tailsCounter++;
cout << "You flipped heads: " << headsCounter "times" << endl;
cout << "You flipped tails: " << tailsCounter "times" << endl;
}