title: Trying to workout the problem in this C# code for Arithmetic Sequence using iteration and recursion
body: <p>This is for a college assignment but I cannot workout what I'm doing wrong. I am new to programming and any help would really be appreciated as this assignment is due in 8 hours. </p>
  
  <p>There is an error on <code>int sum=0</code> where it says </p>
  
  <blockquote>
    <p>"The variable sum is assigned but its value is never used". It also says the same for i and ln. What can I do to solve this issue></p>
  </blockquote>
  
  <pre><code>using System;  
  public class arithmeticSequence
  {  
      public static void Main()
       {
  
        Console.Write("\n\n");    
        Console.Write("------------------------------------------------------------");
        Console.Write("\n\n");    
        Console.Write("Calculates the sum of n numbers in an arithmetic sequence:\n");
        Console.Write("\n\n");    
        Console.Write("------------------------------------------------------------");
        Console.Write("\n\n");    
  
        int x,d,n,i,ln; //x = starting number, n = number of items, d = difference
        int sum=0;
  
  
        Console.Write("Please enter the starting number (x): ");
  x = int.Parse(Console.ReadLine());  
  
        Console.Write("Please enter the number of items (n): ");
  n = int.Parse(Console.ReadLine());  
  
        Console.Write("Please enter the common difference (d): ");
  d = int.Parse(Console.ReadLine());  
  
        Console.WriteLine("Sum of {x} to {d} numbers is {SumByIteration(x, d, n, i, ln, sum)}");
  Console.WriteLine("Sum of {x} to {d} numbers is {SumByRecursion(i, ln, x, n, d, sum)}");
  
  }
  
  static int SumByIteration(int x, int d, int n, int i, int ln, int sum){
       sum = ( n * ( 2 * x + ( n -1 ) * d ) )/ 2;
       ln = x + (n-1) * d;
       Console.Write("\nThe Sum of the  A.P. series are : \n");
  
       for(i=x;i&lt;=ln; i= i + d ){
       if (i != ln)
           Console.Write("{0} + ",i);
       else
           Console.Write("{0} = {1} \n\n",i,sum);
       }return sum;
  }
  
  static int SumByRecursion(int i, int ln, int x, int n, int d, int sum){
      i = x;
      for (x = 1; x &lt; n; x++)
      {
        ln = d + ln + i;
        i = 0;
        sum = sum + ln;
  
      }
      return sum;
  
      }
  
  }
  </code></pre>