Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C++ Noob: DiceGame making each dice roll random

    I've been at this for a while now and am going to need assistance for this one. I got everything nailed down but really I can't get the pair of dices to roll different numbers. If anyone could either toss me a hint or better yet put me out of my misery so I can study the code and note it down for future reference that'll be superb. I tried placing the srand(time(NULL)); from the constructor to the main but each dice rolls the same.

    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <ctime>
    #include <time.h>
    using namespace std;



    class PairOfDice
    {


    private:

    int dice;
    int faceVaule;

    public:

    PairOfDice(){
    srand(time(NULL));
    roll();

    }

    void roll(){
    dice = (rand() % 6) + 1;
    setdiceOne();
    setdiceTwo();
    }


    void setdiceOne(){

    faceVaule = dice;

    }

    int getdiceOne(){

    return faceVaule;

    }

    void setdiceTwo(){

    faceVaule = dice;

    }

    int getdiceTwo(){
    return faceVaule;

    }



    void display(){

    cout << "The first Dice rolled a " << getdiceOne() << "." << endl;

    cout << "The second Dice rolled a " << getdiceTwo() << "." << endl;
    // adding both dices gives an: No operator " < < " matches these operands
    cout << "Adding both dices up you rolled a total of: " << getdiceOne() + getdiceTwo() << endl;
    }


    };

    int _tmain(int argc, _TCHAR* argv[])
    {

    PairOfDice game;

    game.roll();
    game.display();




    return 0;
    }

  • #2
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    gah no edit button, the (// adding both dices gives an: No operator " < < " matches these operands) was resolved.

  • #3
    Regular Coder Nerevarine's Avatar
    Join Date
    Jan 2013
    Location
    Phendrana Drifts, Tallon IV, W-Class
    Posts
    285
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Blog Entries
    3
    If you solved your problem, you should mark this post as resolved.

    Here's how:How to set a thread as resolved?
    Time kills us in our sleep and we watch it happen in our dreams. -K.K.
    THE END-ALL PROGRAMMING REFERENCE: CLICK HERE (Courtesy of Major Payne)
    My username was previously L0adOpt1c. :: Please read this before posting in the HTML/CSS forum.
    Validate your HTML here and your CSS here. :: Need basic HTML/CSS tutorials? Click here, don't post about it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •