Results 1 to 2 of 2
Like Tree1Thanks
  • 1 Post By Newbie999

Math Help - C++ programming. i need help !

  1. #1
    Junior Member
    Joined
    Feb 2013
    From
    Canada
    Posts
    31

    C++ programming. i need help !

    Change your coin-flipping program into a game. Every time heads comes up, the player wins $2, every time tails comes up the player loses a $1. Write a function CalculateTotal that adds up the player’s winnings and losses after 20 flips of a coin.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Mar 2013
    From
    Australia
    Posts
    8
    Thanks
    1

    Re: C++ programming. i need help !

    Generally everyone have different approach. I would recommend you to have different functions for everything.

    I'm not sure with what you need help with. Is it the logic u are having problem with or the language?

    I will just write the algorithm for you

    Before Calculate total is called, we need to determine whether the player lose or not.

    So lets make a new function

    function void tosscoin (int playerwin, int playerlose)
    {
    int rand
    rand(1) << generate random number from 0 - 1. I am not sure how you call it in c++ just reffer to the documentation

    if rand == 0
    pmoney = pmoney + 2 //If the player lose then add 2 dollars to the player's money
    playerwin = playerwin + 1 //Playerwin is a global variable(int)
    else
    pmoney = pmoney -1 //If the player lose then deduct 1 dollar from the money
    playerlose = playerlose + 1 //Playerlose is a global variable(int)

    game = game + 1 //Game is a global variable. Place it before the main function

    If game == 20 // if game has reached round 20 then call Calculate Total that display the total win and lose
    {
    CalculateTotal(playerwin, playerlose)
    }

    }

    Function void Calculatetotal(int playerwin, int playerlose)
    {
    Print playerwin
    Print playerlose

    }
    Last edited by Newbie999; March 21st 2013 at 10:18 PM.
    Thanks from Riana
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 8
    Last Post: February 20th 2013, 07:35 PM
  2. Replies: 3
    Last Post: February 20th 2013, 06:16 PM
  3. Programming For HP 48G+
    Posted in the Calculators Forum
    Replies: 0
    Last Post: February 3rd 2009, 03:09 AM
  4. Replies: 1
    Last Post: November 17th 2008, 03:18 AM
  5. Please help on R programming
    Posted in the Math Software Forum
    Replies: 0
    Last Post: August 16th 2008, 02:51 AM

Search Tags


/mathhelpforum @mathhelpforum