at voidGame (line 106) I'm having difficulty

My task is to apply the technique of stepwise refinement to design an algorithm for the playGame() function, and play the guessing game. The code already works but I don't understand how to to get it in stepwise refinement (top down method), and it should interact with and call other given functions.



[code]
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <time.h>
#include <algorithm>

using namespace std;

/**
* Function to remove a character from a string while keeping the string intact
* @param str the string from which a character will be removed
* @param charToRemove the character you want to remove from the string
*/
void removeCharFromString(string &str, char charToRemove){
str.erase(remove(str.begin(), str.end(), charToRemove), str.end());
}

/**
* Function to read the shapes from shapes.txt
* @param shapes string array to hold the shapes
*/
void readShapes(string shapes[]){
string dummy;
ifstream inFile("shapes.txt");
for (int i = 0; i < 3; ++i){
getline(inFile, dummy);
if (dummy != ""){ //until blank line is found (end of shape) keep reading the file
shapes[i] += dummy;
shapes[i] += '\n';
--i; //if the shape isn't fully read yet, decrement i to keep reading the same shape
}
}
}

/**
* Function to read the words and phrases from dict.txt
* @param dict string array to hold the words and phrases
*/
void readDict(string dict[]){
int numOfWords;
ifstream inDict("dict.txt");
inDict >> numOfWords;
inDict.ignore();
for (int i = 0; i < numOfWords; ++i)
getline(inDict, dict[i]);
}

/**
* Function that asks the user to pick one of the shapes
* @return user selection shape index
*/
int pickShape(){
cout << "Please pick one of the following:" << endl << "1. Car" << endl << "2. Plane" << endl << "3. Farm" << endl;
int selection;
cin >> selection;
return selection-1;
}

/**
* Function get the difficulty from the user which will determine how many letters will be shifted during encryption
* @return a value between 6-9 which is the number of letters shifted6
*/
int askDifficulty(){
int diff;
cout << "Please enter a number between 6-9 to represent difficulty" << endl;
cin >> diff;
while (diff < 6 || diff > 9){
cout << "Difficulty has to be between 6 and 9. Please try again." << endl;
cin >> diff;
}
return diff;
}

/**
* Function to encrypt the selected word or phrase
* @param alphabet string containing all letters in the English alphabet
* @param difficulty number of letters that will be shifted
* @param decrypt the phrase to be encrypted
* @return the encrypted version of the phrase
*/
string encryptWord(string alphabet, int difficulty, string decrypt){
int letterLoc;
string result = "";
for (int i = 0; i < decrypt.length(); ++i){
if (decrypt[i] != ' '){
//find the letter's location in the alphabet and add difficulty for the new letter index
letterLoc = alphabet.find(decrypt[i]);
letterLoc += difficulty;
// go back to the beginning of the alphabet if out of bounds
if (letterLoc > 25)
letterLoc -= 26;
result += alphabet[letterLoc];
}
else
result += ' ';
}
return result;
}

/**
* Function to play the game from start, asking user input and then asking the user to pick letters
* @param shapes string array to hold the shapes
* @param dict string array to hold the words and phrases
*/
void playGame(string shapes[], string dict[]){
//this portion is where I'm confused
}

int main(int argc, const char * argv[]) {
srand (time(NULL));
string shapes[3];
string dict[40];
readShapes(shapes);
readDict(dict);
playGame(shapes, dict);

return 0;
}
[code/]
Topic archived. No new replies allowed.