Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hänga_gubbe
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "saviosa";
            char x;
            int counter = 0;
            string ut = "";
            char[] bokstav = new char[7];
            for (int i = 0; i < s.Length; i++)
            {
                bokstav[i] = 'X';
            }
            do
            {
                ut = "";
                Console.Write("mata in en bokstav: ");
                x = Convert.ToChar(Console.ReadLine());
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] == x)
                        bokstav[i] = x;
                }
                counter++;
                for (int i = 0; i < s.Length; i++)
                {
                    ut = ut + Convert.ToString(bokstav[i]);

                }
                Console.WriteLine(ut);


            } while (counter < s.Length);






            Console.ReadKey();
        }
    }
}
Posted
Updated 10-Feb-14 1:02am
v2
Comments
Kornfeld Eliyahu Peter 10-Feb-14 7:07am    
And the question is?
Allan Wissam 10-Feb-14 7:18am    
how can i make the programm say "congrats you guessed right" when the whole word is visable

1 solution

This should do.

C#
for (int i = 0; i < s.Length; i++)
{
    ut = ut + Convert.ToString(bokstav[i]);
 
}
Console.WriteLine(ut);
//Add this line
if (ut == s) Console.WriteLine("Congrats, you guessed right");

[Edit] Added code for clarification.
 
Share this answer
 
v3
Comments
Allan Wissam 10-Feb-14 8:02am    
dude i dont know how to thank you !! if (ut == s)
{Console.WriteLine("Congrats, you guessed right");} i did this thats why i didnt get result
S Houghtelin 10-Feb-14 8:11am    
Glad to be of service Allen. Du är välkommen. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900