Note that there are some explanatory texts on larger screens.

plurals
  1. POalternative FizzBuzz example error
    primarykey
    data
    text
    <p>Been trying to solve this for 2 days now and I just can't get it to work! The programs layout has to stay the same (part of the challenge). Really bugging me and hoping somebody could shed some light...</p> <p>I keep getting the following error: Use of unassigned local variable 'countOfFizz'<br> Use of unassigned local variable 'countOfBuzz' Use of unassigned local variable 'countOfFizzBuzz' Use of unassigned local variable 'countOfPrime'</p> <p>On these lines: </p> <pre><code>fb.IsFizz(input, countOfFizz); fb.IsFizz(input, countOfBuzz); fb.IsFizz(input, countOfFizzBuzz); fb.IsFizz(input, countOfPrime); </code></pre> <p>and here is the full code. (again apologies if its poor coding, its basics and the layout has been supplied already).</p> <pre><code>class FizzBuzz { public static void Main() { int input; string enter; int countOfFizz; int countOfBuzz; int countOfFizzBuzz; int countOfPrime; Console.WriteLine("Please enter a number: "); enter = Console.ReadLine(); input = int.Parse(enter); while (input != 0) { Console.WriteLine("Please enter a number: "); enter = Console.ReadLine(); input = int.Parse(enter); FizzBuzz fb = new FizzBuzz(); fb.IsFizz(input, countOfFizz); FizzBuzz fb1 = new FizzBuzz(); fb1.IsBuzz(input, countOfBuzz); FizzBuzz fb2 = new FizzBuzz(); fb2.IsFizzBuzz(input, countOfFizzBuzz); FizzBuzz fb3 = new FizzBuzz(); fb3.IsPrime(input, countOfPrime); FizzBuzz fb4 = new FizzBuzz(); fb4.TotalFizz(countOfFizz); FizzBuzz fb5 = new FizzBuzz(); fb5.TotalBuzz(countOfBuzz); FizzBuzz fb6 = new FizzBuzz(); fb6.TotalFizzBuzz(countOfFizzBuzz); FizzBuzz fb7 = new FizzBuzz(); fb7.TotalPrime(countOfPrime); } Console.WriteLine("Finished."); } public bool IsFizz(int input, int countOfFizz) { if (input % 9 == 0) { Console.WriteLine("Fizz"); countOfFizz++; return true; } return false; } public bool IsBuzz(int input, int countOfBuzz) { if (input % 13 == 0) { Console.WriteLine("Buzz"); countOfBuzz++; return true; } return false; } public bool IsFizzBuzz(int input, int countOfFizzBuzz) { if (input % 9 == 0 &amp;&amp; input % 13 == 0) { Console.WriteLine("FizzBuzz"); countOfFizzBuzz++; return true; } return false; } public bool IsPrime(int input, int countOfPrime) { for (int i = 2; i &lt; input; i++) { if (input % i == 0 &amp;&amp; i != input) { return false; } } Console.WriteLine("Prime"); countOfPrime++; return true; } public void BeginTesting(int countOfFizz, int countOfBuzz, int countOfFizzBuzz, int countOfPrime) { countOfFizz = 0; countOfBuzz = 0; countOfFizzBuzz = 0; countOfPrime = 0; } public int TotalFizz(int countOfFizz) { Console.WriteLine("Number of Fizz: "); return countOfFizz; } public int TotalBuzz(int countOfBuzz) { Console.WriteLine("Number of Buzz: "); return countOfBuzz; } public int TotalFizzBuzz(int countOfFizzBuzz) { Console.WriteLine("Number of FizzBuzz: "); return countOfFizzBuzz; } public int TotalPrime(int countOfPrime) { Console.WriteLine("Number of Prime: "); return countOfPrime; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload