logo
down
shadow

Getting a specific letter from a string variable for my simple guessing game for clues


Getting a specific letter from a string variable for my simple guessing game for clues

By : user3099558
Date : January 11 2021, 03:32 PM
hope this fix your issue Basically i have a word guessing game wherein the player has a limit of 4 guesses. in each guess i'd like to show a letter of the word to be guessed example: , Define a clue index in the class:
code :
int clueIndex = 0;
Console.Writeline($"The next letter of the clue is: {secretWord[clueIndex++]}");


Share : facebook icon twitter icon
Simple guessing game continuing with any other letter other than the declared variable Y/N

Simple guessing game continuing with any other letter other than the declared variable Y/N


By : Begia
Date : March 29 2020, 07:55 AM
it should still fix some issue You have an accidental semicolon after that if statement and before your break.
Simple guessing game that allows user to play again after correctly guessing the random number?

Simple guessing game that allows user to play again after correctly guessing the random number?


By : Splixz
Date : March 29 2020, 07:55 AM
wish helps you since my english is not good, i will give you the code ( modifed from yours).
code :
    #include<stdio.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include<time.h>

    int random_num;

    int guessGame(int guessed_num) {


        if (guessed_num == random_num) {
           printf("Correct! That's the number.\n");
           return 1;
        } else if (guessed_num < random_num) {
              printf("Too low. Guess again.\n");
              return 0;
           } else {
              printf("Too high. Guess again.\n");
             return 0;
        }
    }

    int main() {
    char loop;
    while (1) {
    int guessed_num = 0;
    srand(time(NULL));
    random_num = rand() % 50 + 1;
    printf("I have a number between 1-50.\n");
    printf("Can you guess what it is?\n");
    printf("Enter your initial guess.\n");
    while (1) {
        scanf("%d", &guessed_num);
        int returnValue = guessGame(guessed_num);
        if (returnValue == 1) {
            break;
        }
    }
    printf("You wanna do it again? ");
    getchar();
    scanf("%c", &loop);
    if (loop == 'n') {
        break;
    }
}
return 0;
} 
Letter guessing game Java

Letter guessing game Java


By : Michael
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have been working on a java guessing game for letters (a-z)! However i have created the game perfectly by using the number 1-26, but i cannot figure out how to convert each integer to a letter ie a = 1, b = 2,....z = 26!
code :
 public static void main(String args[])
        {
            Scanner scan = new Scanner(System.in);      
            System.out.println("Guess the Letter");
            String myLetter=scan.nextLine();
                //get the letter of myLetter variable then convert to Uppercase
            char enteredLetter=Character.toUpperCase(myLetter.charAt(0));
                    //26 only because the characters array starts with index 0
            char[] characters ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
                    //I had created a parrallel array symbolizing int value of each letter
            int[] range={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26};
            //this variable convert user input to one of the array element of range
            int userInputToInt=0;
            //this variable is for knowing what int[] range array element must the value of userInputToInt fall
            int userInputControlLoop=0;
            char randomLetter=characters[(int)(Math.random()*26)];
            // get the random input of computer convert it to int
            int computerInputToInt=0;

                //this loop is for getting the int value of randomLetter input by the computer
                for(int i=0;i<characters.length;++i)
                {
                    if(randomLetter==characters[i])
                    {

                        computerInputToInt=range[i];
                    }
                }
                //this loop is for getting the int value of user inputted letter
                for(char i:characters)
                {
                    if(enteredLetter==i)
                    {
                        userInputToInt=range[userInputControlLoop];
                    }
                    ++userInputControlLoop;
                }


                 //test the entered letter of user
            if(enteredLetter==randomLetter)
            {
                System.out.println("Correct Guess");
                System.out.println("The letter is:"+randomLetter);
            }
            //test the entered letter of user if greater than computer input
            else if(userInputToInt>computerInputToInt)
            {
                System.out.println("Incorrect Guess");
                System.out.println("The letter is too high");
                System.out.println("The letter is:"+randomLetter);
            }
            //test the entered letter of user if lesser than computer input
            else if(userInputToInt<computerInputToInt)
            {
                System.out.println("Incorrect Guess");
                System.out.println("The letter is too low");
                System.out.println("The letter is:"+randomLetter);
            }

        }
Java guessing letter game

Java guessing letter game


By : user6670856
Date : March 29 2020, 07:55 AM
it helps some times Hi im currently creating a guessing letter game! So far i have made it so you guess between the numbers 1 and 26 using the java.util.random class. However this random number should be converted into the corresponding number within the alphabet! ie a=1 etc..This is where my problem is i dont know how to convert this randomly generated number into a letter! This needs to be related to the integer as i have to able to tell the user if they are above the letter in the alphabet or to low based on the guess they entered! One more thing is that the users guess will be a letter also! Below is my code! Any help will be greatly appreciated!
code :
 Random random = new Random();
 char c = (char) (random.nextInt(26) + 'a');
Python guessing game with clues

Python guessing game with clues


By : user2985033
Date : March 29 2020, 07:55 AM
I wish this helpful for you This is the closest I could get to what you asked for. The comments on your original question are worth a read in my opinion but I think this does exactly what you asked for in the question.
code :
print("The secret number is somewhere between 0 and 100. You have 5 guesses.")
user_input = int(input('Make a guess '))

count = 0
last_distance = -1
while user_input is not 41 and count < 4:
    count = count + 1
    how_close_to_answer = (41 - user_input)
    how_close_to_answer = how_close_to_answer.__abs__()
    if how_close_to_answer <= 5 and last_distance > 5:
        user_input = int(input(f'Hot. Remaining guesses {5 - count} '))
    elif last_distance == -1:
        if 5 < how_close_to_answer < 20:
            user_input = int(input(f'Warm. Remaining guesses {5 - count} '))
        elif how_close_to_answer >= 20:
            user_input = int(input(f'Cold. Remaining guesses {5 - count} '))
        elif how_close_to_answer <= 5:
            user_input = int(input(f'Hot. Remaining guesses {5 - count} '))
    else:
        if how_close_to_answer < last_distance:
            if how_close_to_answer <= 5:
                user_input = int(input(f'Hotter. Remaining guesses {5 - count} '))
            else:
                user_input = int(input(f'Warmer. Remaining guesses {5 - count} '))
        elif how_close_to_answer > last_distance:
            user_input = int(input(f'Colder. Remaining guesses {5 - count} '))
    last_distance = how_close_to_answer


if user_input is not 41:
    print('You Lose!')
else:
    print('You Win!')
    print(f"It took you {count + 1} guesses to get this correct.")
Related Posts Related Posts :
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • How to send new request to redirect URL with new access token
  • Attempt to invoke virtual method on a null object reference Xamarin LockScreen
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org