In: Computer Science
How to write this mini program in C# - (C sharp please)
There are 3 squirrels and winter begins in roughly 12 weeks
Each week, a squirrel will manage to stash away anywhere
from 10 to 20 acorns
Each week, display the following:
◦
The number of weeks before winter
◦
The number of acorns each squirrel stashed away that week
◦
The total number of acorns each squirrel has stashed away
Bonus: display the number of acorns stashed each month as
asterisks (*)
//C# program
using System.IO;
using System;
class Program
{ public static int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
static void Main()
{
int week =12;
int total=0;
int i;
for(i=1;i<=week;i++){
Console.WriteLine("Week before winter " + (week-i));
int s1 = RandomNumber(10,20);
int s2 = RandomNumber(10,20);
int s3 = RandomNumber(10,20);
Console.WriteLine("The number of acorns squirrel1 stashed away in
week " +i+ " is " + s1);
Console.WriteLine("The number of acorns squirrel2 stashed away in
week " +i+ " is " + s2);
Console.WriteLine("The number of acorns squirrel3 stashed away in
week " +i+ " is " + s3);
total+=s1+s2+s3;
if(i%4==0){
Console.WriteLine("\nThe number of acorns stashed in month "+(i/4)+
" : ");
for(int j=0;j<total ;j++){
Console.Write("*");
}
total=0;
Console.WriteLine("\n");
}
}
}
}