Question

In: Computer Science

Using C # Problem: "Tom is from the U.S. Census Bureau and greets Mary at her...

Using C #
Problem: "Tom is from the U.S. Census Bureau and greets Mary at her door. They have the following conversation: Tom: I need to know how old your three kids are. Mary: The product of their ages is 36. Tom: I still don't know their ages. Mary: The sum of their ages is the same as my house number. Tom: I still don't know their ages. Mary: The younger two are twins. Tom: Now I know their ages! Thanks! How old are Mary's kids and what is Mary's house number?"

The solution is 2,2,9, therefore mary's house # is 13
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This is the code i have thus far:

Console.WriteLine("What is the age of the first child");
num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("What is the age of the second child");
num2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("What is the age of the third child");
num3 = Convert.ToInt32(Console.ReadLine());

How do I make it loop until they get the correct answer. (2,2,9) or (2,9,2) or (9,2,2)

If they get the answer wrong, I want the user keep trying again until they enter "quit"

Solutions

Expert Solution

Based on the given data, we can just obtain the possible solutions of their ages. We cannot exactly determine the ages.

Source Code:

using System;
class Sample {
static void Main() {
string val = Console.ReadLine();
int product = Convert.ToInt32(val);
int a,b;
bool flag = false;
//None of the ages is greater than the product.
//Let 'b' be the age of the elder one and 'a' be the age of younger ones.
//Therefore, 'b' must be greater than 'a'
for(a=1;a<=product;a++){
for(b=1;b<=product;b++){
if(a<b && a*a*b == product){
flag = true;
Console.WriteLine();
Console.WriteLine("Ages are " + a + ", " + a + " and " + b);
Console.WriteLine("Mary\'s house number is " + (2*a + b));
}
}
}
if(!flag){
Console.WriteLine("I cannot find their ages");
}
}
}

Output:

Please appreciate the solution if you find it helpful.

If you have any doubts in the solution, feel free to ask me in the comment section.


Related Solutions

Measures of Average: U.S. Census Bureau The U.S. Census Bureau reports the median family income in...
Measures of Average: U.S. Census Bureau The U.S. Census Bureau reports the median family income in its summary of census data. a) Why do you suppose it uses the median instead of the mean? b) What might be the disadvantages of reporting the mean? Measures of Variation: MP3 Player Life Span A company selling a new MP3 player advertises that the player has a mean lifetime of 5 years. If you were in charge of quality control at the factory,...
According to the U.S. Census​ Bureau, the Gini ratio in the U.S. rose from 0.479 to...
According to the U.S. Census​ Bureau, the Gini ratio in the U.S. rose from 0.479 to 0.486 between 2015 and 2018. This implies which of the​ following? A. The area between the Lorenz curve and the line of equality increased from 0.243 in 2015 to 0.521 in 2018. B. The area between the Lorenz curve and the line of equality decreased from 0.521 in 2015 to 0.243 in 2018. C. The Lorenz curve in the U.S. was farther away from...
According to the U.S Census Bureau, the average travel time to work in the U.S. is...
According to the U.S Census Bureau, the average travel time to work in the U.S. is 25.4 minutes. a simple random sample of 10 people reported the following travel times, 10,11,9,24,37,22,75,23,51,48. at a 5% significance level, do the data provide sufficient evidence to conclude that people in Bryan, tx spend less time traveling to work than the national average? calc the p-value. a. p= 0.7838 b. p= 0.4325 c. p= 0.8217 d. p= 0.8067 e. p= 0.1933
According to the U.S Census Bureau, the average travel time to work in the U.S. is...
According to the U.S Census Bureau, the average travel time to work in the U.S. is 25.4 minutes. a simple random sample of 10 people reported the following travel times, 10,11,9,24,37,22,75,23,51,48. at a 5% significance level, do the data provide sufficient evidence to conclude that people in Bryan, tx spend less time traveling to work than the national average? calc the p-value. a. p= 0.7838 b. p= 0.4325 c. p= 0.8217 d. p= 0.8067 e. p= 0.1933
What is Accessibility? A 1997 report by the U.S. Census Bureau categorizes 19.6% of the U.S....
What is Accessibility? A 1997 report by the U.S. Census Bureau categorizes 19.6% of the U.S. population as having some sort of disability. Within that group are individuals with visual, hearing, cognitive, and motor impairments. Each category includes a much wider range of conditions. For example, visual impairments include limited vision, color blindness, and blindness. Disability categories can also include temporary disabilities; for example, someone with a broken wrist may have difficulty using a mouse but still needs access to...
the U.S census bureau defines NAICS code 443141 as consisting of " U.S establishment known as...
the U.S census bureau defines NAICS code 443141 as consisting of " U.S establishment known as appliance stores, primarily engaged in retailing an array of new household appliances, such as refrigerators, dishwashers, ovens, irons, coffeemakers, hair dryers, electric razors, room air- conditions, microwave ovens, sewing machines, and vacuum cleaners, or retailing new appliances in combination appliance repair services." there are more than 48000 stores that fall within this classification. one such establishment is plaza appliance mart, on monroe road in...
According to the U.S. Census Bureau, 11% of children in the United States lived with at...
According to the U.S. Census Bureau, 11% of children in the United States lived with at least one grandparent in 2009 (USA TODAY, June 30, 2011). Suppose that in a recent sample of 1570 children, 224 were found to be living with at least one grandparent. At a 5% significance level, can you conclude that the proportion of all children in the United States who currently live with at least one grandparent is higher than 11%? Use both the p-value...
The Statistical Abstract of the United States published by the U.S. Census Bureau reports that the...
The Statistical Abstract of the United States published by the U.S. Census Bureau reports that the average annual consumption of fresh fruit per person is 99.9 pounds. The standard deviation of fresh fruit consumption is about 30 pounds. Suppose a researcher took a random sample of 38 people and had them keep a record of the fresh fruit they ate for one year. (Round all z values to 2 decimal places. Round your answers to 4 decimal places.) a. What...
According to the Census Bureau, 8.8% of the U.S population had no health insurance coverage in...
According to the Census Bureau, 8.8% of the U.S population had no health insurance coverage in 2017. Suppose that in a recent random sample of 1200 Americans, 130 had no health insurance. Use a 0.02 significance level to test the claim that the current percentage of Americans who have no health insurance coverage is greater than 8.8%. Use the [BLANK] method.
Changes in Education Attainment: USE SOFTWARE - According to the U.S. Census Bureau, the distribution of...
Changes in Education Attainment: USE SOFTWARE - According to the U.S. Census Bureau, the distribution of Highest Education Attainment in U.S. adults aged 25 - 34 in the year 2005 is given in the table below. Census: Highest Education Attainment - 2005   No     High School     Associate's     Bachelor's     Graduate or     Diploma     Diploma     Degree     Degree     Professional Degree   Percent     14%   48%   8%   22%   8% In a survey of 4000 adults aged 25 - 34 in the year 2013, the counts for these levels...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT