problem with a c++ project

basically i need a way for the the dice to be counted as the spot e.g. if i roll a 5 it moves to spot 5 and if on the next turn i roll a 3 i would be at spot 8

#include "stdafx.h"
#include <fstream> // writing to files
#include <iostream> // cin and cout
#include <ctime> // time()
#include <cstdlib> // srand() and rand()

using namespace std;

// FUNCTION HEADERS
void roll_the_dice(int &spot);
void spin_wheel(int &spot);
void pick_card(int& spot, int& card);
void choose_card_wheel(int& spot, int& card);
void check_location(int player, int &spot, int &card);

// global variable seen by all functions
// The file will store game events
ofstream outfile("gamelog.txt");

int main()
{
int player;
int player1_spot = 0, player2_spot = 0;
int card_num;
int dice;
srand(static_cast<unsigned int>(time(0))); // seed the generator

do {
outfile << "\nPlayer 1 - Enter 1 to roll the dice." << endl;
cout << "\nPlayer 1 - Enter 1 to roll the dice." << endl;
cin >> player;
roll_the_dice(player1_spot);
check_location(player, player1_spot, card_num);

if (player1_spot >= 90) break;

outfile << "\nPlayer 2 - Enter 2 to roll the dice." << endl;
cout << "\nPlayer 2 - Enter 2 to roll the dice." << endl;
cin >> player;
roll_the_dice(player2_spot);
check_location(player, player2_spot, card_num);
} while ((true)); // *** REPLACE true with proper condition
}

void roll_the_dice(int &spot)
{
int dice;
srand(time(NULL));
dice = rand() % 6 + 1;
std::cout << "You rolled a " << dice << "." << std::endl;
}

void spin_wheel(int &spot)
{
// *** FILL THIS FUNCTION
}

void pick_card(int& spot, int& card)
{
// *** FILL THIS FUNCTION
}

void choose_card_wheel(int& spot, int& card)
{
int choice;

outfile << "Enter 1 to spin the wheel or 2 to pick a card." << endl;
cout << "Enter 1 to spin the wheel or 2 to pick a card." << endl;
cin >> choice;

if (true) // *** REPLACE true with proper condition
{
spin_wheel(spot);
}
else {
pick_card(spot, card);
}
}

void check_location(int player, int &spot, int &card)
{
int choose;
spot = 0 + 'dice';
outfile << "You landed on spot " << spot << endl;
cout << "You landed on spot " << spot << endl;

if (spot == 30)
{
outfile << "You get the shortcut to 70." << endl;
cout << "You get the shortcut to 70." << endl;
spot = 70;
}
if (spot == 10 || spot == 60)
{
pick_card(spot, card);
}
if (spot >= 90)

{
outfile << "Player " << player << " wins!" << endl;
cout << "Player " << player << " wins!" << endl;
}
else
{
outfile << "Keep playing." << endl;
cout << "Keep playing." << endl;
}
}


Untested but...
This should do it.

1
2
3
4
5
6
7
8
9
10
11
12
void roll_the_dice(int &spot) {
  int dice;

  srand(time(NULL));
  dice = rand() % 6 + 1;

  // add dice to current spot
  spot += dice;

  std::cout << "You rolled a " << dice << "." << std::endl;
  std::cout << "Your new spot is " << spot << "." << std::endl;
}
Last edited on
@Bdanielz i wish i could reach through the screen and hi5 you
Last edited on
Topic archived. No new replies allowed.