Hello,
I have an error on this line in main.cpp file:
EGuessStatus Status = BCGame.CheckGuessValidity(Guess)
and I do not why.
main.cpp
/* This is the console executable, that makes use of the BullCow class This acts as the view on MVC pattern, and is responsible for all user interaction. Tod gme logig see the BullCowGame class. */ #include <iostream> #include <string> #include "FBullCowGame.h" using FText = std::string; using int32 = int; void PrintIntro(); void PlayGame(); FText GetGuess(); bool AskToPlayAgain(); FBullCowGame BCGame; // instantiate a new game // the entry point form the app int main() { bool bPlayAgain = false; do { PrintIntro(); PlayGame(); // TODO: add a game summary bPlayAgain = AskToPlayAgain(); } while (bPlayAgain); return 0; // exit the app } void PlayGame() { BCGame.Reset(); int32 MaxTries = BCGame.GetMaxTries(); // loop for the number of turns asking for guessing for (int32 count = 1; count <= MaxTries; count++) // TODO change rfom FOR to WHILE loop once we are validating tries { FText Guess = GetGuess(); //TODO make loop checking valid guess //Submit valid guess to the game FBullCowCount BullCowCount = BCGame.SubmitGuess(Guess); EGuessStatus Status = BCGame.CheckGuessValidity(Guess); // print number of bulls and cows //std::cout << "Bulls = " << BullCowCount.Bulls; std::cout << "Bulls = " << BullCowCount.Bulls; std::cout << ". Cows = " << BullCowCount.Cows << std::endl; } } // introduce the game void PrintIntro() { std::cout << "Welcome to Bulls and Cows" << std::endl; std::cout << "Can you guess the " << >BCGame.GetHiddenWordLength(); std::cout << " letter isogram I am thinking of?\n"; std::cout << std::endl; return; } FText GetGuess() // TODO Get valid guess { int32 CurrentTry = BCGame.GetCurrentTry(); std::cout << "Try " << CurrentTry << ". Enter your guess: "; FText Guess = ""; std::getline(std::cin, Guess); // repeat the guess back std::cout << "Your guess was: " << Guess << std::endl; return Guess; } bool AskToPlayAgain() { std::cout << "Do you want to play again? (y/n)"; FText Response = ""; std::getline(std::cin, Response); return (Response[0] == 'y') || (Response [0] == 'Y'); }
FBullCowGame.h
#pragma once
#include <string>
using FString = std::string;
using int32 = int;
// all values initializing to 0
struct FBullCowCount
{
public:
int32 Bulls = 0;
int32 Cows = 0;
};
enum class EGuessStatus
{
OK,
Not_Isogram,
Wrong_Length,
Not_Lowercase
};
class FBullCowGame
{
public:
FBullCowGame();
int32 GetMaxTries() const;
int32 GetCurrentTry() const;
int32 GetHiddenWordLength() const;
bool IsGameWon() const;
EGuessStatus CheckGuessValidity(FString) const;
bool CheckGuessValidity(FString);
void Reset(); // TODO make a more rich return value.
FBullCowCount SubmitGuess(FString);
// Please try and ignore these and focus on the interfase above ^^
private:
// See constructor for initialisation.
int32 MyMaxTries;
int32 MyCurrentTry;
FString MyHiddenWord;
};
FBullCowGame.cpp
#include "FBullCowGame.h"
using int32 = int;
FBullCowGame::FBullCowGame()
{
Reset();
}
int32 FBullCowGame::GetMaxTries() const { return MyMaxTries; }
int32 FBullCowGame::GetCurrentTry() const { return MyCurrentTry; }
int32 FBullCowGame::GetHiddenWordLength() const { return MyHiddenWord.length(); }
void FBullCowGame::Reset()
{
constexpr int32 MAX_TRIES = 8;
const FString HIDDEN_WORD = "planet";
MyCurrentTry = 1;
MyMaxTries = MAX_TRIES;
MyHiddenWord = HIDDEN_WORD;
return;
}
bool FBullCowGame::IsGameWon() const
{
return false;
}
EGuessStatus FBullCowGame::CheckGuessValidity(FString) const
{
if (false)
{
return EGuessStatus::Not_Isogram;
}
else if (false)
{
return EGuessStatus::Not_Lowercase;
}
else if(false)
{
return EGuessStatus::Wrong_Length;
}
else
{
return EGuessStatus::OK;
}
}
// receives a VALID guess, increments turn, and return valid guess
FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
// increment the turn number
MyCurrentTry++;
// stup a return variable
FBullCowCount BullCowCount;
int32 HiddenWordLength = MyHiddenWord.length();
// loop throuth all letters in the guess
for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++)
{
// compare letters against the hidden word
for (int32 GChar = 0; GChar < HiddenWordLength; GChar++)
{
if (Guess[GChar] == MyHiddenWord[MHWChar] )
{
if (MHWChar == GChar)
{
BullCowCount.Bulls++;
}
else
{
BullCowCount.Cows++;
}
}
// if they match then
}
}
// if they are in the same place
// increment bulls
// else
// increment cows if not
return BullCowCount;
}
I am sorry that i didnât include the error.
Severity Code Description Project File Line Suppression State
Error C2440 âinitializingâ: cannot convert from âboolâ to âEGuessStatusâ BullCowGame e:\onedrive\udemy\cppunreal\section_02\bullcowgame\main.cpp 46