2010/04/14

Exam preparation C# Random number

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


 

namespace ConsoleApplication4

{


//Random number


//Someone select number and bet money.


//If this number much the random number, he will play again and select number again.


//If not, he will lose money.


//And programming ask him whether he wants to play again or not.


class
Program

{


static
void Main(string[] args)

{


//Initialize Random


Random rd = new
Random();


 


//Declare variable for while roop


int h=0;


 


//He plays at least one time. After playing, he chose to play again or not.


do

{


 


//Ask him to select number


Console.WriteLine("Pay $5.00 and select numbaer from 1-6.");


 


//Generate random number


int rd1 = 1 + rd.Next(6);


 


//Display random number for Debug


Console.WriteLine("Random number " + rd1);


 


//Read input data


string input1=Console.ReadLine();


 


//Convert from string to interger


int i=int.Parse(input1);


 


//Check to mutch input number and random number


if (i == rd1)

{


//Display congraturations and ask 2nd number


Console.WriteLine("Congraturations!! First much!");


Console.WriteLine("Please select 2nd number from 1-6.");


 


//Generate 2nd random numbaer


int rd2 = 1 + rd.Next(6);


 


//Display 2nd random number for debug


Console.WriteLine("2nd rndom number " + rd2);


 


//Read input 2nd data


string input2 = Console.ReadLine();


 


//Convert from string to interger


int k = int.Parse(input2);


 


//Check to much 2nd input number and 2nd random number


if (k == rd2)

{


//Display congraturations


Console.WriteLine("Congraturations!! Second much!!");


Console.WriteLine("You win this game and get $1,000.00!!");


break;

}


else

{


//Display his loose


Console.WriteLine("Sorry you lose this game.");

}

}


else

{


//Display his loose


Console.WriteLine("Sorry you lose this game.");

}


//Ask him to play again or not


Console.WriteLine("Do you want to play again? Yes-1 No-0");


 


//Read input data


string input3 = Console.ReadLine();


 


//Convert from string to integer

h = int.Parse(input3);


 


//End of do while loop

}while(h==1);


 


//Display good bye


Console.WriteLine("Good bye! See you!!");


 

}

}

}

0 件のコメント:

コメントを投稿

UA-9417263-1