Wrong output in loops



// 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);

}

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

{

if(bGameOver)

{

    ClearScreen();

    SetupGame();

}

else//checkinng PlayerGuess

{

        ProcessGuess(Input);

     

}

}

void UBullCowCartridge::SetupGame()

{

 //telling the user what to do

PrintLine(TEXT("Bull Cows"));  

   

//Promt Player For Guess

HiddenWord = TEXT("cake");

Lives = HiddenWord.Len( );

bGameOver =false;

PrintLine(TEXT("Guess The %i Letter Word!"),HiddenWord.Len());

PrintLine(TEXT("you have %i lives "),HiddenWord.Len());



IsIsogram(HiddenWord);

}

void UBullCowCartridge::EndGame()

{

bGameOver = true;

PrintLine(TEXT("\nPress Enter To Play Again."));

}

void UBullCowCartridge::ProcessGuess(FString Guess)

{

if (Guess==HiddenWord)

    {

        PrintLine(TEXT("You Won!"));  

        EndGame();

        return;

    }

 if (Guess.Len() != HiddenWord.Len())    

            {

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

                PrintLine(TEXT("Sorry Try Guessing again!\nYou Have  lives Remaining"));

                return;

            }



// Check If Isogram

if (!IsIsogram(Guess))

{

    PrintLine(TEXT("No Repeating Letters, guess again"));

    return;

}

// Remove Life

PrintLine(TEXT("Lost a live"));

--Lives;

if(Lives<=0)

    {

        ClearScreen();  

        PrintLine(TEXT("You have no lives left"));

        PrintLine(TEXT("The Hidden Word Was %s"),*HiddenWord);

        EndGame();  

        return;

    }  

else

    {

       

    }

       

//Show the player Bulls and Cows

PrintLine(TEXT("Guess Again, you have %i Lives Left"),Lives);

}

bool UBullCowCartridge::IsIsogram(FString Word) const

{

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

{

    PrintLine(TEXT("%c"),Word[Index]);

}

// for each letter

// start with letter[0]

// compare it with next letter

// until we reach [word.len()-1]

// if any are same then return false

return true;

}

Whenever you paste code please ensure that it is formatted correctly and that you use a code block. That code is almost impossible to read.

With that said, what’s wrong with the output?

I figured it out I was using IsIsogram(HiddenWord);

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

Privacy & Terms