trouble with a C++ PROJECT

I really don't know how to implement this Spin the wheel function, it's supposed to send a player backwards or forwards a certain amount of spots

// boardgame1.cpp : Defines the entry point for the console application.
//

#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;
spot += dice;

std::cout << "You rolled a " << dice << "." << std::endl;

}

void spin_wheel(int &spot)
{
int spin;
srand(time(NULL));
spin = rand() % 8 + 1;


std::cout << "go " << spin << "." << std::endl;

if (spin == 1)
{
outfile << "Move foreward 1 space." << endl;
cout << "Move foreward 1 space." << endl;
spot += spin;
}

if (spin == 2)
{
outfile << "Move backward 7 spaces." << endl;
cout << "Move backwards 7 spaces." << endl;
spot += spin;
}

if (spin == 3)
{
outfile << "Move foreward 8 spaces." << endl;
cout << "Move foreward 8 spaces." << endl;
spot += spin;
}

if (spin == 4)
{
outfile << "go back to the beginning." << endl;
cout << "go back to the beginning." << endl;
spot += spin;
}
}

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;

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;
}
}
srand(time(NULL));
just do this once in your program somewhere, not all over the place. Its not "wrong" its just not the intent. The intent is to seed once and use the stream of values from that.

I don't see an issue, except you stopped coding... spin function looks ok as far as it goes but needs code for all values 1-8, right? What isn't right about it?
@Jonnin say if on the spin i get a 2, it's supposed to move backwards 8 spots.. but it doesn't do that and i have no idea how i would do that
I don't know your rules, but that looks like

if (... == 2)
spot -= 8;

much like what you already did.

if the board is circular, you might be able to add and use modulus (%) to wrap back to the first location using only adds.
Last edited on
@Jonnin thanks that seems to have solved it
Topic archived. No new replies allowed.