Getting an Error In the Return Type lecture 82

[1/2] Compile [x64] BullCowCartridge.cpp
E:\cowBull\BullCowGame-starter-kit\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(115): error C2143: syntax error: missing ‘;’ before ‘UBullCowCartridge::GetBullCows’
E:\cowBull\BullCowGame-starter-kit\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(115): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
E:\cowBull\BullCowGame-starter-kit\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(116): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
E:\cowBull\BullCowGame-starter-kit\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(116): error C2556: ‘int UBullCowCartridge::GetBullCows(const FString &) const’: overloaded function differs only by return type from ‘UBullCowCartridge::FBullCowCount UBullCowCartridge::GetBullCows(const FString &) const’
E:\cowBull\BullCowGame-starter-kit\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.h(27): note: see declaration of ‘UBullCowCartridge::GetBullCows’
E:\cowBull\BullCowGame-starter-kit\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.cpp(115): error C2371: ‘UBullCowCartridge::GetBullCows’: redefinition; different basic types
E:\cowBull\BullCowGame-starter-kit\BullCowGame-starter-kit\Source\BullCowGame\BullCowCartridge.h(27): note: see declaration of ‘UBullCowCartridge::GetBullCows’
[2/2] Compile [x64] BullCowCartridge.gen.cpp
Build failed.



Would need to see the full code as the error is before line 115, that’s just where the compiler saw something unexpected. Though based on your indentation, it looks like you’re missing an } for the previous function.

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

#include “BullCowCartridge.h”

#include “HiddenWord.h”

//#include"math/UnrealMathUtility.h"

void UBullCowCartridge::BeginPlay() // When the game starts

{

Super::BeginPlay();

IsIsograms = GetValidWords(Words);

SetupGame();    

}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter

{

if(bGameOver)

{

   ClearScreen();

   SetupGame();

}

else

{

    ProcessGuess(Input);

}

}

void UBullCowCartridge::SetupGame()

{

PrintLine(TEXT("Welcome To BullCow Game"));

HiddenWord =IsIsograms[FMath::RandRange(0,IsIsograms.Num()  -1 )];

Lives=HiddenWord.Len()*2;  

bGameOver = false;

PrintLine(TEXT("Guess the %i letter word!.."),HiddenWord.Len());

PrintLine(TEXT("Type in your guess \nPress enter to continue..."));

PrintLine(TEXT("The hidden word is %s. "),*HiddenWord);

}

void UBullCowCartridge::EndGame()

{

bGameOver =true;

PrintLine(TEXT(“Press Enter To Play Again”));

}

void UBullCowCartridge::ProcessGuess(const FString& Guess)

{

if (Guess == HiddenWord && Lives > 0)

{

    PrintLine(TEXT("You have won!!"));

    EndGame();  

}



else if (Guess.Len() != HiddenWord.Len() ) // Assuming the hidden word length is always 4 characters

{

    PrintLine(TEXT("The Hidden Word is %i characters long"),HiddenWord.Len());

   

}



else if(Lives>0)

{

    Lives = Lives - 1;

    PrintLine(TEXT("Wrong Input\nLives Left :%i\nTry Again"),Lives);

    FBullCowCount Score = GetBullCows(Guess);

    PrintLine(TEXT("You Have %i Bulls and %i Cows"), Score.Bulls,Score.Cows);

    return;

}



else if (Lives == 0)

{

    PrintLine(TEXT("No Lives Left!.."));    

    EndGame();

}

if(!IsIsogram(Guess))

{

    PrintLine(TEXT("No repeating letter,Guess Again!!"));

    return;

}

}

bool UBullCowCartridge::IsIsogram(const FString& Word) const

{

for (int32 Index = 0; Index < Word.Len(); Index++)

{

    for (int32 Comparison = Index+1; Comparison < Word.Len(); Comparison++)

    {

        if (Word[Index]== Word[Comparison])

    {

        return false;

    }

       

    }

   

}

 return true;

}

TArray<FString> UBullCowCartridge::GetValidWords(const TArray<FString>& WordList) const

{

  TArray<FString> ValidWords;

for(FString Word : WordList)

{

    if(Word.Len()>=4 && Word.Len()<=8 && IsIsogram(Word))

    {  

       

            ValidWords.Emplace(Word);

       

    }

}  

return ValidWords;

}

FBullCowCount UBullCowCartridge::GetBullCows(const FString& Guess) const

{

FBullCowCount Count;

for(int32 GuessIndex =0;GuessIndex< Guess.Len();GuessIndex++)

{

    if(Guess[GuessIndex]==HiddenWord[GuessIndex])

    {

        Count.Bulls++;

        continue;

    }

    for (int32 HiddenIndex = 0; HiddenIndex < HiddenWord.Len(); HiddenIndex++)

    {

        if(Guess[GuessIndex]==HiddenWord[HiddenIndex])

        {

            Count.Cows++;

            break;

        }

    }

   

}

return Count;

}

just got the correction

I have just written the stuct inside the class

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

Privacy & Terms