logo CodeStepByStep logo


Write a method named FlipCoins that accepts as its parameter a string for an input file name. Assume that the input file data represents results of sets of coin flips that are either heads (H) or tails (T) in either upper or lower case, separated by at least one space. Your method should consider each line to be a separate set of coin flips and should output to the console the number of heads and the percentage of heads in that line, rounded down to the nearest integer (truncated). If this percentage is more than 50%, you should print a "There were more heads!" message. For example, consider the following input file:

T t   t T h  H

For the input above, your method should produce the following output:

3 heads (60%)
There were more heads!

2 heads (33%)

1 heads (100%)
There were more heads!

The format of your output must exactly match that shown above. You may assume that the file exists and contains at least 1 line of input, that each line contains at least one token, and that no tokens other than h, H, t, or T will be in the lines.

Method: Write a C# method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.