View the step-by-step solution to:

I am new to c# coding with visual works and keep getting an error message. I have UNDERLINED the line where I am getting the visual studio (MAC OSX)...

I am new to c# coding with visual works and keep getting an error message. I have UNDERLINED the line where I am getting the visual studio (MAC OSX) error message: "operator cannot be applied to operands of type "char" and char CS0019" Please HELP. I am creating a Hangman Game.


Assignment Instructions:

Modify the design and program to test if each letter the user entered is one of the letters in the word. If the letter guessed is in the word, display a message to the user that they guessed correctly, if not display a message that the user guessed incorrectly. Add a score variable that will keep track of the number of incorrect guesses. If the user guesses incorrectly, increment the score variable. Display the score at the end of the program.


using System;

namespace hangmangame

{

    class MainClass

    {

        static void Main(string[] args)

        {

            //hangman word is last name and variables

            char letter1 = 'J';

            char letter2 = 'A';

            char letter3 = 'J';

            char letter4 = 'A';

            char letter;

            int score = 0;

            //welcome message

            Console.WriteLine("Welcome to the Hangman Game!");

            Console.WriteLine("Enter a letter please: ");

            letter = char.Parse(Console.ReadLine());

            Console.WriteLine(" ");

            if (letter = letter1 || letter = letter2 || letter = letter3 || letter = letter4)

            {

                Console.WriteLine("You have guessed correctly!");

            }

            else

            {

                score++;

                Console.WriteLine("Incorrect. Try again!");

                Console.WriteLine("You have " + score + " incorrect guesses.");

            }

            //guess2

            Console.WriteLine("Enter another letter please: ");

            letter = char.Parse(Console.ReadLine());

            Console.WriteLine(" ");

            if (letter == letter1 || letter == letter2 || letter == letter3 || letter == letter4)

            {

                Console.WriteLine("You have guessed correctly!");

            }

            else

            {

                score++;

                Console.WriteLine("Incorrect. Try again!");

                Console.WriteLine("You have " + score + " incorrect guesses.");

            }

            //guess3

            Console.WriteLine("Enter a letter please: ");

            letter = char.Parse(Console.ReadLine());

            Console.Write(" ");

            if (letter == letter1 || letter == letter2 || letter == letter3 || letter == letter4)

            {

                Console.Write("nYou have guessed correctly!");

            }

            else

            {

                score++;

                Console.Write("nSorry, you have guessed incorrectly!");

                Console.Write("nYou have " + score + " incorrect guesses.");

            }

            //guess4

            Console.Write("nnEnter a letter please: ");

            letter = char.Parse(Console.ReadLine());

            Console.Write(" ");

            if (letter == letter1 || letter == letter2 || letter == letter3 || letter == letter4)

            {

                Console.Write("nYou have guessed correctly!");

            }

            else

            {

                score++;

                Console.Write("nSorry, you have guessed incorrectly!");

                Console.Write("nYou have " + score + " incorrect guesses.");

            }

            

            Console.ReadLine();

        }

    }

}

Top Answer

Executed Code in C# using System; public class Program { public static void Main () {     char [] new1 = new char [ 26 ];... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online