0% found this document useful (0 votes)
91 views

Gussing Game Source Code in C#

This document contains code for a number guessing game program with three difficulty levels - easy (numbers 1-10), normal (numbers 1-100), and hard (numbers 1-1000). The program generates a random number, allows the user to guess, and informs them if their guess is too high or too low. It counts the number of guesses and ends the game when the user guesses correctly or reaches the maximum number of allowed guesses, declaring a win or loss accordingly.

Uploaded by

Amit Zioni
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views

Gussing Game Source Code in C#

This document contains code for a number guessing game program with three difficulty levels - easy (numbers 1-10), normal (numbers 1-100), and hard (numbers 1-1000). The program generates a random number, allows the user to guess, and informs them if their guess is too high or too low. It counts the number of guesses and ends the game when the user guesses correctly or reaches the maximum number of allowed guesses, declaring a win or loss accordingly.

Uploaded by

Amit Zioni
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace data_man
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcom To Data Man!!! =D");
Console.WriteLine("Pick Level");
Console.WriteLine("<E/e>-easy 4 guesses,nums from 1-10");
Console.WriteLine("<N/n>-easy 8 guesses,nums from 1-100");
Console.WriteLine("<H/h>-easy 15 guesses,nums from 1-1000");

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


if(quest=='e' || quest=='E')
{
int nisayon;
int guess=0;
Random r=new Random();
int a=r.Next(1,11);
while(guess<4)
{
Console.WriteLine("write guess");
nisayon=int.Parse(Console.ReadLine());

if(nisayon==a)
{
break;
}
else
if(nisayon<a)
{
Console.WriteLine("too low");
guess++;
}
else
if(nisayon>a)
{
Console.WriteLine("too high");
guess++;
}
}
if(guess==4)
{
Console.WriteLine("you lose =q ");
Console.WriteLine("the num was: "+a);
}
else
{
Console.WriteLine(" you win! =D");
}
}
if(quest=='N' || quest=='n')
{
int nisayon;
int guess=0;
Random r=new Random();
int a=r.Next(1,101);
while(guess<8)
{
Console.WriteLine("write guess");
nisayon=int.Parse(Console.ReadLine());

if(nisayon==a)
{
break;
}
else
if(nisayon<a)
{
Console.WriteLine("too low");
guess++;
}
else
if(nisayon>a)
{
Console.WriteLine("too high");
guess++;
}
}
if(guess==8)
{
Console.WriteLine("you lose =q ");
Console.WriteLine("the num was: "+a);
}
else
{
Console.WriteLine(" you win! =D");
}
}
if(quest=='h' || quest=='H')
{
int nisayon;
int guess=0;
Random r=new Random();
int a=r.Next(1,1001);
while(guess<15)
{
Console.WriteLine("write guess");
nisayon=int.Parse(Console.ReadLine());

if(nisayon==a)
{
break;
}
else
if(nisayon<a)
{
Console.WriteLine("too low");
guess++;
}
else
if(nisayon>a)
{
Console.WriteLine("too high");
guess++;
}
}
if(guess==15)
{
Console.WriteLine("you lose =q ");
Console.WriteLine("the num was: "+a);
}
else
{
Console.WriteLine(" you win! =D");
}
}

}
}
}

You might also like