Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Random rnd = new Random();
- int x; // random number
- int sum = 0; // sum of the random numbers
- int c = 0; // number of trials
- // stop the game if trials>=15 or sum>=30
- while (sum < 30 && c < 15)
- {
- // get another random number
- x = rnd.Next(1, 7);
- // increase the counter
- c = c + 1;
- Console.WriteLine(x);
- // if x==4 start sum from zero
- if (x == 4)
- {
- sum = 0;
- }
- else
- {
- // if not 4 add it to sum
- sum = sum + x; //sum += x;
- }
- Console.WriteLine("The sum is {0}", sum);
- }
- // if the game stopped, check if winner or loser
- if (sum < 30)
- {
- Console.WriteLine("No more! you lose");
- }
- else
- {
- Console.WriteLine("You Win !!!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement