logo CodeStepByStep logo

FlipCoins

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:

H T H H T
T t   t T h  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.

Type your C# solution code here:


This is a method exercise. Write a C# method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.