Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

struct Player {
    string name;
    int money;
    string one;
};

char secretPhrase[] = "Easy as pie";
char mask[sizeof(secretPhrase) - 1];


void displayBlankPhrase(char p[], char g)
{
        for (int i = 0; i < sizeof(secretPhrase)-1 ; i++)
        {

            if (secretPhrase[i] == g) 
                mask[i] = g;
        }
        for (int i = 0; i < sizeof(mask); i++)
            cout << mask[i];

        cout << endl;
    }

void init()
{
    //Initialize Mask
    for (int i = 0; i < sizeof(secretPhrase) - 1; i++)
    {
        if (secretPhrase[i] == ' ')
            mask[i] = ' ';
        else {
            mask[i] = '*';
        }
    }
}

bool isGameOver() {
    for (int i = 0; i < sizeof(mask) - 1; i++)
        if(mask[i] == '*')
                    return false;

    return true;
}

int main()
{
    // Initializes mask array
    init();

    //Welcome Screen | This is where you enter player information

    Player one;
    one.money = 0;
    cout << "Welcome to 'Wheel of Fortune'!" << endl;
        cout << "What is your name?: ";
        cin >> one.name;
    cout << "Hello " << one.name << 
        ". You starting amount is $" << Player().money << "." << endl;


    // WHEEL
    int wheelSlots[24];
    wheelSlots[0] = 0;
    wheelSlots[1] = 1;
    wheelSlots[2] = 50;
    wheelSlots[4] = 200;    
    wheelSlots[3] = 1000;
    wheelSlots[5] = 3000;
    wheelSlots[6] = 400;
    wheelSlots[7] = 0;
    wheelSlots[8] = 5000;
    wheelSlots[9] = 600;
    wheelSlots[10] = 10;
    wheelSlots[11] = 300;
    wheelSlots[12] = 500;
    wheelSlots[13] = 8000;
    wheelSlots[14] = 25;
    wheelSlots[15] = 400;
    wheelSlots[16] = 125;
    wheelSlots[17] = 10000;
    wheelSlots[18] = 0;
    wheelSlots[19] = 300;
    wheelSlots[20] = 250;
    wheelSlots[21] = 600;
    wheelSlots[22] = 400;
    wheelSlots[23] = 50;

    int playersMenu = 0;
    int playerOptions;
    char playersChoice;
    bool gamePlay = true;
    bool playerWin = false;
    int playerSpins = 0;
    int spin;
    string playerSolve;

;

while (gamePlay == true && playerWin == false) {
    if (playerSpins < 1) {
        //Checks to see if play has spun the wheel
        cout << "Spin the wheel to start the game..." << endl;
        playerOptions = 2;
        for (int i = 0; i < sizeof(secretPhrase) - 1; i++) {
            secretPhrase[i] = '-';
        }
    }
    else {
        cout << "\n\n Choose an option?: " << endl
            << "1. Guess a letter" << endl
            << "2. Spin the wheel" << endl
            << "3. Buy a vowel (- $500)" << endl
            << "4. Solve the puzzle" << endl;
        cin >> playerOptions;
    }
    playersChoice = '*';
    // Evaluate players options options 1-4
    if (playersMenu == 1) {
        cout << "Guess a letter for $: " << playerSpins;
        cin >> playersChoice;

    }
    if (playersMenu == 2){
        playerSpins++;
    // Random wheel number generator
    spin = rand() % 25;
    cout << endl << "The wheel landed on: $" << wheelSlots[spin] << "." << endl;
    if (spin == 0 || spin == 1) {
        one.money = 0;
        cout << "OH NO! Bankrupt!" << endl;
    }
}

    if(playersMenu == 3){
        one.money -= 250;
        cout << "Here is your money now: $" << one.money << ". " << "Guess a vowel: ";
        cin >> playersChoice;
    }
    if(playersMenu == 4){

        cout << "You want to solve (no caps please and use underscores for spaces):"; // Underscores because of time constraints.
        cin >> playerSolve;
        if (playerSolve == secretPhrase) {
            cout << "You win!" << endl;
            playerWin = true;
            gamePlay = false;
        }
    }
}


return  0;
}


What I have tried:

I am trying to create a wheel of fortune game, but having issues with my code being stuck in an infinite loop after entering the players name. PLEASE HELP!!! Could someone please look over my code or test it in their own environment. I really have now idea what is I am missing or need to change to break out of this loop
Posted
Updated 19-Jun-16 16:45pm
Comments
Andreas Gieriet 19-Jun-16 21:54pm    
Why do you think you are in an infinite loop? What is the symptom? What is the last text you see on the screen?
BTW: Your player has no start money, and you do not print his money (you should call one.money and not Player().money).
You also have wrong index calculation in rand() % 25 - you only have indices 0...23, so it should be ...% 24.
Regards
Andi

1 - Open Debugger
2 - Set Breakpoint at suspected problem
3 - run program
4 - step through loop and see what it fails exit condition.


Remember: loops can be created by you explicitly (if,while, do, etc.) but they may also be the result of an event handlers, unintentionally. For example, an on-change event that itself causes a change could call itself in a loop.
 
Share this answer
 
Start by cleaning up the code
void displayBlankPhrase(char p[], char g)

p is never used and seems to have no function
cout << "Hello " << one.name << 
        ". You starting amount is $" << Player().money << "." << endl;

Shouldn't Player().Money be one.money
int playersMenu = 0;
...
// Evaluate players options options 1-4
if (playersMenu == 1) {...
if (playersMenu == 2) {....
if (playersMenu == 3) {...
if (playersMenu == 4) {...

playersMenu starts at 0 but the if statement options you give for this only include 1,2,3,4 ... you lost me it does nothing with 0?????

Convert the if statements to a switch(playerMenu) layout it would be a lot easier to read.

I gave up at this point to many errors to work out what you are doing.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900