Exercise 4: Given 2 jars A and B. Jar A has 5000 marbles initially and Jar B has 1000 marbles initially.
57 marbles are remove from A and added to B. How many days are need for jar B to have more marbles than jar A?" (Use a while or a do-while loop)
(Hint: you need a counter to count the numbers of days the condition cannot be set based on counter because you don't know how many days are needed for the above condition to occur.)
static void Main(string[] args)
{
int jarA = 5000;
int jarB = 1000;
int days = 0;
do
{
jarA -= 57;
jarB += 57;
days++;
Console.WriteLine("day: {0} jarA: {1} jarB:{2}", days, jarA, jarB);
} while (jarA > jarB);
Console.ReadLine();
}
No comments:
Post a Comment