I'm creating a Wheel of Fortune program, and I have just started. Currently I'm just trying to take a word from a file and transfer it into an array, and with that create an array with the same size, but full of asterisks (*'s). My class is making me use certain function prototypes, which makes it so that I can't change them around and I'm stuck trying to make an array inside of a function. Here is my code:
/* GLOBAL HEADERS */
#include <iostream> // include standard I/O library
#include <iomanip> // include IO manipulators
#include <fstream> // include file streaming
#include <string> // include C++ string class
#include <cctype> // for the isalpha function
#include <ctime> // to access the computer's clock
#include <cstdlib> // needed for rand() and RAND_MAX
using namespace std; // access standard namespace
/* =========================================================================*/
/* GLOBAL NAMED CONSTANTS */
const int WHEEL_SIZE = 15; //Number of entries in the wheel,
const int PHRASE_SIZE = 81; // int [optional if you use only
// string class objects and no Cstrings
// or array of char]
const int NUM_PLAYERS = 3; // Number of players in game
const int BANKRUPT = 0; // Entry on the wheel that signifies bankrupt
const int LOSE_TURN = -1; // Entry on the wheel that signifies lose a turn
const int VOWEL_COST = 250; //Cost to buy a vowel
const int wheel[WHEEL_SIZE] =
{50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 1000, 1500,
2500, BANKRUPT, LOSE_TURN};
/*==========================================================================*/
/* GLOBAL VARIABLES */
/*==========================================================================*/
/* GLOBAL FUNCTION PROTOTYPES */
void Open_Data_File (ifstream&);
int initialize_arrays(string&, string&);
/*==========================================================================*/
/* MAIN FUNCTION */
int main ()
{
string phrase; // to store the phrase array
string puzzle; // to store the puzzle * array
initialize_arrays(phrase, puzzle); //opens the initialize_arrays function
return (0);
}
/*==========================================================================*/
int initialize_arrays(string& phrase, string& puzzle)
/*
This function should ask for the input file, open the input file, read the
character string into the phrase array and place the appropriate *s in the
puzzle array. For each alphabetic character in the phrase array, a respective
* belongs in the puzzle array. If the character is not an alphabetic character
(i.e., ‘-’, ‘!’, etc.) then the character is copied into the puzzle array.
You must do the usual error checking, i.e., if the file name is invalid,
loop until you obtain a valid file name from the user*/
{
string filename; // name of file as input by user
ifstream inFile;
int count = 0;
// ask for file name and try to open
cout << "Enter a file name which cannot contain blanks: ";
cin >> filename;
inFile.open (filename.c_str());
// error handling loop: if file does not open, ask user again until it does
while (!inFile)
{
inFile.clear();
cout << "Please try agian. Enter a file name: ";
cin >> filename;
inFile.open(filename.c_str());
}
for (count = 0; count < PHRASE_SIZE; count++)
inFile >> phrase[count];
// Close the file.
inFile.close();
return(count);
I havn't gotten everything done yet, but I cant seem to figure out a way to actually create a "phrase" array without it giving me an error message about mixing the string& with a phrase[PHRASE_SIZE] but I also cant change the function to accept phrase as a phrase originally.