samedi 28 février 2015

I keep getting the error "The variable 'b' is being used without being initialized, and I'm not sure how to fix it



//Benjamin McKinney
//CSCI 2010-10
//Spring 2015
//PASS 3

//Programmed on Windows 8.1 using Visual C++ 2010 Express

//This program plays the game MasterMind

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

struct Player
{
string Name;
int HighScores[6];
bool CheatOn;
};

struct Board
{
int NumHoles;
int Holes[6];
};

struct Guess
{
int Count;
int NumHoles;
int Holes;
};

void printHighScores(string);
void readHighScore(string);
void updateHighScore(string, int);
string getPlayer();
int getBoard();
void playGame(string);
void menu(string);

int main()
{
Player p;
srand((unsigned int)time(0));

cout << "!!! Benjamin McKinney's Master-MasterMind!!!\n";
cout << "--------------------------------------------\n";

getPlayer();
menu(p.Name);

cout << "Goodbye, " << p.Name << endl;
printHighScores(p.Name);

cout << "----------------------------------------------\n";
cout << "!!! Benjamin McKinney's Master-MasterMind!!!\n";

system("PAUSE");
return 0;
}

void printHighScores(string name)
{
return;
}

void readHighScore(string)
{
return;
}

void updateHighScore(string, int)
{
return;
}

string getPlayer()
{
Player p;
cout << "What is your name?\n";
cin >> p.Name;
cout << "Welcome, " << p.Name << endl;
p.CheatOn = false;
readHighScore(p.Name);
return p.Name;
}

int getBoard()
{
Board b;

cout << "Enter the number of holes you would like: ";
cin >> b.NumHoles;

if(b.NumHoles > 6 || b.NumHoles < 1)
{
cout << "Error! You must pick a number between 1 and 6! Try again!\n";
}

for(int i=0;i<b.NumHoles;i++)
{
b.Holes[i] = rand() % 2 + 1;
}

return b.NumHoles;
}

void playGame(string)
{
Player p;
Board b;
Guess g;
getBoard();

g.Count=0;

for(int i=0;i<b.NumHoles;i++)
{
cout << "Enter your guess for the row\n";
if(p.CheatOn == true)
{
for(int a=0;a<(sizeof(b.Holes)-1);a++)
{
cout << b.Holes[a];
}
}
cout << "Enter your guess for hole " << i << ": ";
cin >> g.Holes;
g.Count++;
}

return;
}

void menu(string)
{
Player p;
char choice;

cout << "Please choose an option below:\n";
cout << "\t P)lay\n\t Q)uit\n\tChoice: ";
cin >> choice;

if(choice == 'P')
playGame(p.Name);
else
if(choice == 'Q')
return;
else`enter code here`
if(choice == 'C')
{
p.CheatOn = true;
playGame(p.Name);
}
}


Ignore the three HighScore functions, but otherwise I can't get this to work... "Run-Time Check Failure #3 - The variable 'b' is being used without being initialized." is the main issue that I'm having. If anyone can help me I would really appreciate it. Thanks!




Aucun commentaire:

Enregistrer un commentaire