How can I trace back the error - c++

I was assigned to create an array check (to see if the array is increasing, decreasing, or neither [then exiting if neither]) and a recursive binary search for one of my assignments. I was able to do these things after some help from my peers, but I need help in finding what seems to be causing the error
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
Aborted
when running the code. I Googled this error and this error seems to be vague or I just am not understanding. It compiles without errors, but I need help in what finding what I did wrong. It is able to run without the binarySearchR function and its associating code, as the array check on its own was the previous assignment. Below is the code, and I thank you so much in advance!
#include <iosteam>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;
int checkArraySort (string *fileLines, int numberOfLines);
int binarySearchR (string *fileLines, string searchKey, int iMin, int iMax);
int main ()
{
int numberOfLines = 0;
string searchKey = 0;
cout << "Input search key: ";
cin >> searchKey;
ifstream fileIn;
fileIn.open("words_in.txt");
string line;
if (fileIn.eof()) /* Checks file to see if it is blank before proceeding */
{
exit (EXIT_SUCCESS);
}
else
{
while(!(fileIn.eof()))
{
fileIn >> line;
numberOfLines++;
}
fileIn.close(); /* closes fileIn, need to reopen to reset the line location */
fileIn.open("words_in.txt");
string *fileInLines;
fileInLines = new string[numberOfLines];
for (int i = 0; i < numberOfLines; i++)
{
fileIn >> line;
fileInLines[i] = line;
}
fileIn.close(); /* closes fileIn */
int resultingCheck = checkArraySort(fileInLines, numberOfLines);
if (resultingCheck == -1)
{
cout << "The array is sorted in descending order." << endl;
}
else if (resultingCheck == 1)
{
cout << "The array is sorted in ascending order." << endl;
}
else
{
cerr << "ERROR: Array not sorted!" << endl;
exit (EXIT_FAILURE);
}
int searchResult = binarySearchR (fileInLines, searchKey, 0, numberOfLines);
if (!searchResult == -1)
{
cout << "Key found at index " << searchResult << "." << endl;
}
else
{
cout << "Key not found at any index." << endl;
}
exit (EXIT_SUCCESS);
}
}
int checkArraySort (string *fileLines, int numberOfLines)
{
int result = 1; /* Ascending by default */
for (int i = 1; i < numberOfLines; i++) /* Checks if decending */
{
if (fileLines[i] < fileLines[i-1])
{
result = -1;
}
}
if (result == -1) /* Makes sure it is descending (or if it is neither) */
{
for (int i = 1; i < numberOfLines; i++)
{
if (fileLines[i] > fileLines[i-1])
{
result = 0;
}
}
}
return result;
}
int binarySearchR (string *fileLines, string searchKey, int iMin, int iMax)
{
// so, its gotta look at the center value and each times, it discards half of the remaining list.
if (iMax < iMin) /* If the minimum is greater than the maximum */
{
return -1;
}
else
{
int iMid = (iMin + iMax) / 2;
if (fileLines[iMid] > searchKey) /* If the key is in the lower subset */
{
return binarySearchR (fileLines, searchKey, iMin, iMid - 1);
}
else if (fileLines[iMid] < searchKey) /*If the key is in the upper subset */
{
return binarySearchR (fileLines, searchKey, iMin, iMid + 1);
}
else /*If anything else besides the two */
{
return iMid;
}
}
}

The easy way: add a bunch of cout s to see where you program goes and what the values are.
Pros
Easy to do
Cons
Requires a recompile each time you want to add more info
The hard way: Learn to use a debugger
Pros
Can inspect "on the fly"
Don't need to rebuild
Can use what you learn in every other C++ program
Cons
Requires a bit of research to learn how to do it.

Related

Read file line by line using ifstream in CPP and Customize code to print number of frequency and percentage

The genetic code is the set of rules used by living cells to translate information encoded within genetic material (DNA or mRNA sequences of nucleotide triplets, or codons) into proteins. The genetic code is highly similar among all organisms and can be expressed in a simple table with 64 entries.
A three-nucleotide codon in a nucleic acid sequence specifies a single amino acid. The vast majority of genes are encoded with a single scheme often referred to as the genetic code (refer to the codon table).
Attached to this assignment, you will find a text file named “mouse.dat” that contains the complete genome of a mouse. Write a program to read in the DNA sequence from the file, calculate the frequency of each codon in the codon table, and print out the result as a number and a percentage.
(a) Write a serial code for the solution "Normal Code by using C++ Language".
When I compiled the above code I got the below error message "Unable to open file mouse.dat: No such file or directory"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
int main()
{
std::vector<string> codons = { "ttt" }; // Better always initialize any variable or array or objects to zero or NULL or empty string.
codons.push_back("ttc"); // { "ttt", "ttc"
codons.push_back("tta"); // { "ttt", "ttc", "tta"
codons.push_back("ttg"); // { "ttt", "ttc", "tta", ...
codons.push_back("tct");
codons.push_back("tcc");
codons.push_back("tca");
codons.push_back("tcg");
codons.push_back("tat");
codons.push_back("tac");
codons.push_back("taa");
codons.push_back("tag");
codons.push_back("tgt");
codons.push_back("tgc");
codons.push_back("tga");
codons.push_back("tgg");
codons.push_back("ctt");
codons.push_back("ctc");
codons.push_back("cta");
codons.push_back("ctg");
codons.push_back("cct");
codons.push_back("ccc");
codons.push_back("cca");
codons.push_back("ccg");
codons.push_back("cat");
codons.push_back("cac");
codons.push_back("caa");
codons.push_back("cag");
codons.push_back("cgt");
codons.push_back("cgc");
codons.push_back("cga");
codons.push_back("cgg");
codons.push_back("att");
codons.push_back("atc");
codons.push_back("ata");
codons.push_back("atg");
codons.push_back("act");
codons.push_back("acc");
codons.push_back("aca");
codons.push_back("acg");
codons.push_back("aat");
codons.push_back("aac");
codons.push_back("aaa");
codons.push_back("aag");
codons.push_back("agt");
codons.push_back("agc");
codons.push_back("aga");
codons.push_back("agg");
codons.push_back("gtt");
codons.push_back("gtc");
codons.push_back("gta");
codons.push_back("gtg");
codons.push_back("gct");
codons.push_back("gcc");
codons.push_back("gca");
codons.push_back("gcg");
codons.push_back("gat");
codons.push_back("gac");
codons.push_back("gaa");
codons.push_back("gag");
codons.push_back("ggt");
codons.push_back("ggc");
codons.push_back("gga");
codons.push_back("ggg"); // // { "ttt", "ttc", "tta", ..., "ggg"}
// codons.size() is 64
vector<int> counts(64, 0);
string line = ""; // Always initialize.
// int numberOfLines=0; // warning: unused variable numberOfLines
char my_character = '\0'; // Always initialize.
for (int indx = 0; 64 > indx; indx++) // Better compare using "number comparison variable" way
{
string codon_req = codons[indx];
ifstream myfile("mouse.dat");
if (myfile.is_open())
{
int cnt = 0, ans = 0;
while (!myfile.eof())
{
myfile.get(my_character);
// If number of count "cnt" becomes 3 reinitialize that to zero.
// and increase "ans" count
if (3 == cnt)
{
ans++;
cnt = 0;
}
if ('\n' == my_character)
{
continue;
}
// Here comparison is not done sequential
// Search if first charater (example t at ttt) is present
// increase cnt
// Next time if it is not present
// compare until we find next letter t
// if found increase cnt at that time.
// Hence ans count is more greater than expected count on word ttt
// NOT SURE ON YOUR PROJECT REQUIREMENT.
if (my_character == (char)codon_req[cnt])
{
cnt++;
}
}
myfile.close();
counts[indx] = ans;
}
else
{
perror("Unable to open file mouse.dat");
exit(1);
}
}
for (int indx = 0; 64 > indx; indx++) //// Better compare using "number comparison variable" way
{
cout << "Before counts[indx] " << counts[indx] << "\n";
codons[indx] = codons[indx] + " " + to_string(counts[indx]);
cout << "After counts[indx] " << counts[indx] << "\n";
}
ofstream newFile("results.txt");
if (newFile.fail())
{
perror("Opening results.txt file failed");
exit(2);
}
else
{
for (int indx = 0; 64 > indx; indx++) /// Better compare using "number comparison variable" way
{
newFile << codons[indx] << '\n';
}
newFile.close();
}
return 0;
}
END

Stack Program in C++

I want to implement a code in my program where it guesses whether or not the given series of operations and corresponding return values from an input file are operating as a stack. In other words, the output is fully determined by the input file.
The text file (StackTest.txt):
4
INSERT 2
INSERT 1
REMOVE 1
REMOVE 2
6
INSERT 5
INSERT 10
INSERT 12
REMOVE 10
REMOVE 5
REMOVE 12
2
INSERT 8
REMOVE 8
Expected Output(from input file):
stack
not stack
stack
However, I'm stuck on how to implement this feature into my current code.
If anyone can help me out on how to achieve the expected output above or give me some hints, I would really appreciate it!
Code in progress...
#include <iostream>
#include <fstream>
#include <string>
#include <stack>
using namespace std;
// Function to check validity of stack sequence
bool validStackSeq(string input, int len)
{
// maintain count of popped elements
int j = 0;
// an empty stack
stack <int> s;
for(int i = 0; i < len; i++)
{
s.push(input[i]);
// check if appended value is next to be popped out
while (!s.empty() && j < len && s.top() == input[j])
{
s.pop();
j++;
}
}
return j == len;
}
int main()
{
ifstream inFile;
string data;
string command;
int num;
inFile.open("StackTest.txt");
//cout << "Reading file..." << endl;
stack <int> s;
while(getline(inFile, data))
{
if(command == "INSERT")
{
s.push(num);
}
else if(command == "REMOVE")
{
s.pop();
}
num = sizeof(data)/sizeof(data[0]);
cout << (validStackSeq(data, num) ? "Stack" : "Not Stack") << endl;
}
inFile.close();
}
Current Output
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack
Stack Validation Program (without input file)
#include <iostream>
#include <stack>
using namespace std;
bool validStackSeq(int pushed[], int popped[], int len)
{
int j = 0;
stack <int> pt;
for(int i = 0; i < len; i++)
{
pt.push(pushed[i]);
while (!pt.empty() && j < len && pt.top() == popped[j])
{
pt.pop();
j++;
}
}
return j == len;
}
// Driver code
int main()
{
int pushed[] = {2, 1};
int popped[] = {1, 2};
int len = sizeof(pushed)/sizeof(pushed[0]);
int pushed1[] = {5, 10, 12};
int popped1[] = {12, 5, 10};
int len1 = sizeof(pushed1)/sizeof(pushed1[0]);
int pushed2[] = {8};
int popped2[] = {8};
int len2 = sizeof(pushed2)/sizeof(pushed2[0]);
int pushed3[] = {1, 4};
int popped3[] = {4};
int len3 = sizeof(pushed3)/sizeof(pushed3[0]);
cout << (validStackSeq(pushed, popped, len) ? "Stack" : "Not Stack") << endl;
cout << (validStackSeq(pushed1, popped1, len1) ? "Stack" : "Not Stack") << endl;
cout << (validStackSeq(pushed2, popped2, len2) ? "Stack" : "Not Stack") << endl;
cout << (validStackSeq(pushed3, popped3, len3) ? "Stack" : "Not Stack") << endl;
return 0;
}
Perform the INSERT and REMOVE operations as specified in the text file. The result is 'stack' if all remove operations are possible (do not occur when the stack is empty) and the operand of each remove operation equals the actual value poped from your stack.
UPDATED 2020-02-29
You cannot create two separate arrays for INSERT and REMOVE operations and process them independently, because the result depends on how the operations are interleaved. For example
INSERT 1
INSERT 2
REMOVE 2
REMOVE 1
should result in stack, but if we move one REMOVE operation up:
INSERT 1
REMOVE 2
INSERT 2
REMOVE 1
the result will become not stack. It means that you need to process the operations in exactly same order as they appear in the file.
The general structure of the code:
ifstream inFile;
inFile.open("StackTest.txt");
int num;
while (inFile >> num) { // Read number of INSERT/REMOVE in each test set
stack<int> s;
bool isStack = true;
for (int i = 0; i < num; i++) {
// Read and process all INSERT/REMOVE operations in this test set
// Set isStack to false if not stack behavior detected
}
cout << (isStack ? "stack" : "not stack") << endl;
}
inFile.close();
As we read the operations from the input file we try to perform them. The INSERT operations should be performed as-is, no checks are required.
if (operation == "INSERT") {
s.push(argument);
}
The REMOVE operations require two checks to be performed: whether the stack is empty and whether the top of stack contains the same number as the argument of the REMOVE operation. If either of the checks fail then we set isStack to false.
if (operation == "REMOVE") {
if (s.empty() || s.top() != argument) {
isStack = false;
}
if (!s.empty()) {
s.pop ();
}
}
Combining this together we get:
#include <iostream>
#include <fstream>
#include <string>
#include <stack>
using namespace std;
int main () {
ifstream inFile;
inFile.open("StackTest.txt");
int num;
while (inFile >> num) {
stack<int> s;
bool isStack = true;
for (int i = 0; i < num; i++) {
string operation;
int argument;
inFile >> operation >> argument;
if (!isStack)
continue;
if (operation == "INSERT") {
s.push(argument);
}
else if (operation == "REMOVE") {
if (s.empty() || s.top() != argument) {
isStack = false;
}
if (!s.empty()) {
s.pop ();
}
}
}
cout << (isStack ? "stack" : "not stack") << endl;
}
inFile.close();
}
There is just one more thing to mention: after we read the operation name and its argument from the file we do a check
if (!isStack)
continue;
This statement is not required, it's there just for a performance improvement. If we already detected that the given test set does not correspond to a stack then we don't need to perform all the remaining operations in this test set, we just skip them. You can safely remove this statement without influencing the result.

Code Gives No Errors but Does Nothing in Command Prompt

I am having trouble getting my code to run on command prompt, I am getting no errors but when I run the code nothing happens.
#include <iostream>
#include <stdexcept>
using namespace std;
//defines the maximum queue size
#define MAX_QUE_SIZE 10
//creates the "rules" for the queue
class queue {
private:
int A[MAX_QUE_SIZE];
int front;
int rear;
public:
queue() {
front = -1;
rear = -1;
}
//checks to see if the queue is empty
bool isEmpty() {
return (front == -1 && rear == -1);
}
//checks to see if the queue if full
bool isFull() {
return (rear + 1) % MAX_QUE_SIZE == front ? true : false;
}
//checks to see if the queue is full, if not then it adds to the queue.
//if so it gives an error message.
void enqueue(int element) {
if (isFull()) {
throw std::overflow_error("QUEUE FULL");
}
if (isEmpty()) {
front = 0;
rear = 0;
}
else {
rear = (rear + 1) % MAX_QUE_SIZE;
}
A[rear] = element;
}
//checks to see if the queue is empty, if not then it deletes from the queue
//if sos it gives an error message.
void dequeue() {
if (isEmpty()) {
throw std::underflow_error("QUEUE EMPTY");
}
else if (front == rear) {
rear = -1;
front = -1;
}
else {
front = (front + 1) % MAX_QUE_SIZE;
}
}
//checks to see if the queue is empty, if so it gives a message saying so
//if not then it prints all the items in the queue
void printqueue() {
if (isEmpty()) {
cout << "EMPTY QUEUE";
}
else {
int count = (rear + MAX_QUE_SIZE - front) % MAX_QUE_SIZE + 1;
cout << "Queue : ";
for (int i = 0; i < count; i++) {
int index = (front + i) % MAX_QUE_SIZE;
cout << A[index] << " ";
}
cout << "\n\n";
}
}
};
int main()
{
queue Q; // creating an instance of Queue.
int i;
int k = 0;
int x;
std::cout << "Please enter some integers (enter 0 to exit):\n";
//a do-while statement that adds to the queue
do {
std::cin >> i;
//tries to add to the queue, if the queue is full it gives and overflow error
try {
Q.enqueue(i);
}
catch (std::overflow_error e) {
std::cout << e.what() << endl;
}
} while (i != 0);
std::cout << endl;
Q.printqueue();
std:cout << "How many values do you want to dequeue:\n";
std::cin >> x;
cout << endl;
//a for loop that dequeues the number of items the user wants to delete
//try the foor loop and dequeue function, if the queue is empty then it gives an underflow error
try {
for (int k = 0; k < x; k++) {
Q.dequeue();
}
}
catch (std::underflow_error e) {
std::cout << e.what() << endl;
}
Q.printqueue();
return 0;
}
I am also typing in g++ -o ehQue ehQue.cpp to compile it. I am not sure if this is causing the error or if my code itself is causing the error. Any amount of help will be appreciated.
I suspect you're just not executing your code. It compiles and runs.
You're compiling the program (not executing it) with:
g++ -o ehQue ehQue.cpp
The command can be understood as calling the program "g++" which should be just an alias to "gcc" which is the compiler. It takes sources code and produces object code, which is then linked to produce an executable binary (program.)
-o ehQue
Is the command parameter to specify the output file name. The compiler will take the provided files and (attempt to) produce a working executable called "ehQue".
ehQue.cpp
Is your source code, which you specified to the compiler.
Within your terminal (where you typed the g++ command) you will, also, need to call the program using a command such as:
./ehQue
Or to be specific to the Windows command prompt:
ehQue
Where you should find that your program runs.
(Tangential) Unless you specifically need to re-invent the wheel, one of CPP's defining features is the Standard Template Library (STL) which is part of the core specification... wrapping a std::deque in a class with your print functions would be advisable.

How to correctly create a ofstream of a struct vector? (abort() is called)

I'm currently building a game and in this part my goal is to update a previously created file of High Scores ("rank.txt")
To do so, I've created a couple of functions so they can read what's in the txt file and so it can update it. Though the reading is ok, while adding the update function it gives me an error and tells me abort() has been called.
void highScoresUpdate(vector<PlayerInfo> player)
{
// This function is responsible for updating the High Scores Table present in the RANK.TXT file
vector<HighScoresStruct> highScores_temp;
HighScoresStruct temp;
ofstream out_file_3("rank.txt");
highScores_temp = readHighScores("rank.txt");
for (int k = 0; k < player.size(); k++)
{
player[k].name = temp.name;
player[k].score = temp.score;
player[k].time = temp.time;
highScores_temp.push_back(temp);
}
sort(highScores_temp.begin(), highScores_temp.end(), compareByScore);
for (int i = 0; i < highScores_temp.size(); i++)
{
out_file_3 << highScores_temp[i].name << endl << highScores_temp[i].score << endl << highScores_temp[i].time << endl;
}
out_file_3.close();
}
For background information, so i don't spam this thread with code all you need to know is that readHighScores is the function responsible for extracting information from the txt file and placing it on a vector .
The structs and comparebyScore funtion are listed below.
bool compareByScore(const HighScoresStruct &a, const HighScoresStruct &b)
{
if (a.score < b.score)
return true;
else if (a.score == b.score)
{
if (a.time > b.time)
return true;
else
return false;
}
else
return false;
}
struct PlayerInfo
{
string name;
unsigned int score;
vector<char> hand;
bool inGame;
unsigned int time;
};
struct HighScoresStruct
{
string name;
unsigned int score;
unsigned int time;
};
So... Can anyone help me?

Call to function is ambiguous in C++. Candidate functions are the Prototype and the function itself

I am working through Stanford CS106B C++ assignments and I have a 'semantic issue' with an assignment.
It seems as if the compiler cannot deduce whether the call is to a function or to the prototype of the function. I don't understand why a call would ever be made to the prototype. How can I make it so that the call is made to the function rather than the prototype? The error message I get it "Call to 'humansTurn' is ambiguous".
The error messages relate to the calls of the humansTurn(Lexicon,Lexicon) function, within the humansTurn(Lexicon,Lexicon) function, at the bottom of the page. The prototype for this function is above the main function.
Any help would be greatly appreciated.
Kind regards,
Mehul
/*
* File: Boggle.cpp
* ----------------
*/
#include <iostream>
#include "gboggle.h"
#include "graphics.h"
#include "grid.h"
#include "vector.h"
#include "lexicon.h"
#include "random.h"
#include "simpio.h"
using namespace std;
/* Constants */
const int BOGGLE_WINDOW_WIDTH = 650;
const int BOGGLE_WINDOW_HEIGHT = 350;
const string STANDARD_CUBES[16] = {
"AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS",
"AOOTTW", "CIMOTU", "DEILRX", "DELRVY",
"DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
"EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"
};
const string BIG_BOGGLE_CUBES[25] = {
"AAAFRS", "AAEEEE", "AAFIRS", "ADENNN", "AEEEEM",
"AEEGMU", "AEGMNN", "AFIRSY", "BJKQXZ", "CCNSTW",
"CEIILT", "CEILPT", "CEIPST", "DDLNOR", "DDHNOT",
"DHHLOR", "DHLNOR", "EIIITT", "EMOTTT", "ENSSSU",
"FIPRSY", "GORRVW", "HIPRRY", "NOOTUW", "OOOTTU"
};
/* Function prototypes */
void welcome();
void giveInstructions();
// Create random board
static Grid <char> randomBoard();
// Create custom board
static Grid<char> customBoard();
static void drawAndFillBoard(Grid<char>);
static void humansTurn(Lexicon,Lexicon);
int main() {
initGraphics(BOGGLE_WINDOW_WIDTH, BOGGLE_WINDOW_HEIGHT);
welcome();
giveInstructions();
string custom = getLine("Type y to create custom board:" );
Grid<char> gridData;
if (custom=="y"){
gridData = customBoard();
} else {
gridData = randomBoard();
}
drawAndFillBoard(gridData);
Lexicon english("EnglishWords.dat");
// Lexicon holds words previously encountered
Lexicon previousWords;
humansTurn(english, previousWords);
return 0;
}
/*
* Function: welcome
* Usage: welcome();
* -----------------
* Print out a cheery welcome message.
*/
void welcome() {
cout << "Welcome! You're about to play an intense game " << endl;
}
/*
* Function: giveInstructions
* Usage: giveInstructions();
* --------------------------
* Print out the instructions for the user.
*/
void giveInstructions() {
cout << endl;
cout << "The boggle board is a grid onto which I ";
cout << "or triple your paltry score." << endl << endl;
cout << "Hit return when you're ready...";
getLine();
}
static Grid<char> randomBoard(){
Vector<string> standardCubes;
for(int i = 0; i<16;i++){
standardCubes.add(STANDARD_CUBES[i]);
}
// Shuffle cubes
for (int i = 0; i < standardCubes.size(); i++) {
int r = randomInteger(i, standardCubes.size()-1);
if (i!=r){
string stringToMove1 = standardCubes.get(i);
string stringToMove2 = standardCubes.get(r);
standardCubes.set(r, stringToMove1);
standardCubes.set(i, stringToMove2);
}
}
// Update grid with random side of cube
Grid<char> gridData(4, 4);
int counter = 0;
for (int columnNo = 0; columnNo <4; columnNo++){
for (int rowNo = 0; rowNo<4; rowNo++) {
string s = standardCubes.get(counter);
int r = randomInteger(0, 5);
gridData[columnNo][rowNo] = s[r];
counter++;
}
}
return gridData;
}
static Grid<char> customBoard(){
Grid<char> gridData(4,4);
string s = getLine("Please enter 16 characters to make up the custom board. Characters will fill the board left to right, top to bottom: ");
for (int i = 0; i < s.length(); i++) {
s[i] = toupper(s[i]);
}
if (s.length()<16){
cout << "String has to be 16 characters long, try again" << endl;
customBoard();
}
int i =0;
for (int columnNo = 0; columnNo <4; columnNo++){
for (int rowNo = 0; rowNo<4; rowNo++) {
gridData[columnNo][rowNo] = s[i];
i++;
}
}
return gridData;
}
static void drawAndFillBoard(Grid<char> gridData){
drawBoard(4, 4);
for (int columnNo = 0; columnNo <4; columnNo++){
for (int rowNo = 0; rowNo<4; rowNo++) {
labelCube(rowNo, columnNo, gridData[rowNo][columnNo]);
}
}
}
static void humansTurn(Lexicon englishWords, Lexicon &previousWords){
/*
Human’s turn (except for finding words on the board). Write the loop that allows the user to enter words. Reject words that have already been entered or that don’t meet the minimum word length or that aren’t in the lexicon. Use the gboggle functions to add words to the graphical display and keep score.
*/
string humanGuess = getLine("Please enter your guess: ");
for (int i = 0; i < humanGuess.length(); i++) {
humanGuess[i] = tolower(humanGuess[i]);
}
if (humanGuess.length()<4){
cout << "Min guess length is four characters" << endl;
humansTurn(englishWords, previousWords);
}
if (!englishWords.contains(humanGuess)) {
cout << "That word is not English, please try another word" << endl;
humansTurn(englishWords, previousWords);
}
if (previousWords.contains(humanGuess)){
cout << "That word has already been guessed, please try another word" << endl;
humansTurn(englishWords, previousWords);
}
// check if word can be made using data on board
}
Your function humansTurn definition has different signature with declaration
function declaration:
static void humansTurn(Lexicon,Lexicon);
Function definition:
static void humansTurn(Lexicon englishWords, Lexicon &previousWords)
^^
//Here