66. Looping in C++ - There are two errors

Hi!
I faced two errors and it seems I did something wrong or maybe accidentally broke the code.
Could anybody help to identify where is the mistake here?
Please see below the screenshot of where the errors are and the code I have so far. Thank you!

image

// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();

    SetupGame();

    PrintLine(TEXT("The HiddenWord is: %s."), *HiddenWord); // Debug Line
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    // int32 a = 1;
    // int32 b = ++a;
    // int32 c = ++ ++a;
    // int32 d = a += 2;
    // int32 e = a++;

    // PrintLine(TEXT("%i, %i, %i, %i, %i"), a, b, c, d, e);

    if (bGameOver)
    {
        ClearScreen();
        SetupGame();
    }
    else // Checking PlayerGuess
    {
        ProcessGuess(Input);
    }

}

void UBullCowCartridge::SetupGame()
{
    // Welcoming the player
    PrintLine(TEXT("Hi! Welcome to the Bull Cows Game!"));
    
    HiddenWord = TEXT("cakes");
    Lives = HiddenWord.Len();
    bGameOver = false;
    
    PrintLine(TEXT("Guess the %i letter word"), HiddenWord.Len());
    PrintLine(TEXT("Your have %i lives."), Lives);    
    PrintLine(TEXT("Type in your guess \nand press Enter to Continue...")); // Prompt player for guess

    // const TCHAR HW[] = TEXT("plums");
    // PrintLine(TEXT("Character 1 of the hidden word is: %c"), HiddenWord[0]); // print "c"
    // PrintLine(TEXT("The 4th character of HW is: %c"), HW[3]); // prints "m"
    
    int32 i = 0;
    while (i < 10)
    {
        PrintLine(TEXT("%i"), i);
        i++;
    }

    for (int32 Index = 0; Index < 2; Index++)
    {
        PrintLine(TEXT("%i"), Index);
    }

    int32 j = 0;
    do
    {
        PrintLine(TEXT("%i"), j);
        j++;
    } while (j < 2);
    
    
void UBullCowCartridge::EndGame()
{
    bGameOver = true;
    PrintLine(TEXT("\nPress enter to play again."));
}

void UBullCowCartridge::ProcessGuess(FString Guess)
{
        if (Guess == HiddenWord)
        {
            PrintLine(TEXT("You have won!"));
            EndGame();
            return;
        }

    // Check If Isogram
    if (!IsIsogram(Guess))
    {
        PrintLine(TEXT("No repeating letters, guess again"));
        return;
    }

            if (Guess.Len() != HiddenWord.Len())
            {
                PrintLine(TEXT("The hidden word is %i letters long"), HiddenWord.Len());
                PrintLine(TEXT("Sorry, try guessing again! \nYou have %i lives remaining"), Lives);
                return;
            }

    // Remove Life
        PrintLine(TEXT("Lost a life!"));
        --Lives;

        if (Lives <= 0)
        {
            ClearScreen();
            PrintLine(TEXT("You have no lives left!"));
            PrintLine(TEXT("The hidden word was: %s"), *HiddenWord);
            EndGame();
            return;
        } 
     
    // show the player the buuls and cows
    PrintLine(TEXT("Guess again, you have %i lives left"), Lives);
}


bool UBullCowCartridge::IsIsogram(FString Word) const
{
    // For each letter 
    // Start at element [0].
    // Compare against the next letter. 
    // Until we reach [Word.Len() -1].
    // if any are the same return false

    return true;
}

Do you have a

void EndGame();

Definition in your Header File?

Yes, I have (see below the header file’s code)

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Console/Cartridge.h"
#include "BullCowCartridge.generated.h"

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BULLCOWGAME_API UBullCowCartridge : public UCartridge
{
	GENERATED_BODY()

	public:
	virtual void BeginPlay() override;
	virtual void OnInput(const FString& Input) override;
	void SetupGame();
	void EndGame();
	void ProcessGuess(FString Guess);
	bool IsIsogram(FString Word) const;

	// Your declarations go below!
	private:
	FString HiddenWord;
	int32 Lives;
	bool bGameOver;
};

you are missing the

}

in the line above the EndGame Function

Much appreciated! Now, this mistake looks so obvious…

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms