title: Simple Calculator class in a C# Console Application
body: <p>I am beginner at c# and i have a homework , so i need your help , here is what i have done for now, </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace SimpleCalculator{
  
      class SimpleCalculator {
  
          double number1;
          double number2;
          double result;
          double stored;
          Boolean isStored; 
  
          public SimpleCalculator()  {}
  
          public double Add()
          {
              result = (this.number1 + this.number2);
              return result;
          }
          public double Subtract()
          {
              result = (this.number1 - this.number2);
              return result;
          }
          public double Multiply()
          {
              result = (this.number1 * this.number2);
              return result;
          }
          public double Divide()
          {
              result = ((this.number1) /( this.number2));
              return result;
          }
          public double SquareRootNumber1()
          {
              result = Math.Sqrt(this.number1);
              return result;
          }
          public double SquareRootNumber2()
          {
              result = Math.Sqrt(this.number2);
              return result;
          }
          public Boolean isMemoryUsed()
          {
              if (this.stored == 0){
                  this.isStored=false ;
                  return isStored;
              }
              else              
                  this.isStored = true;          
              return this.isStored;
          }
          public double  MemoryStore(double paramater_store1) {
              this.stored = this.stored + paramater_store1;
              return this.stored;        
          }
          public double MemoryRecall()
          {       
              if (MemoryStore(this.stored)==0)
                  return 0;  
              else 
                  return MemoryStore(this.stored);       
          }
          public double MemoryAdd(double paramater_store2)
          {
              this.stored = this.stored + paramater_store2 ;
              return this.stored;
          }
          public double MemorySubtract(double paramater_store3)
          {
              this.stored = this.stored - paramater_store3;
              return this.stored;
          }
          public double MemoryClear()
          {
              return this.stored = 0;
          }
  
          static void Main(string[] args)
          {
  
              SimpleCalculator calc = new SimpleCalculator();
              calc.number1 = 3.14; 
              calc.number2 = 5.78;
              Console.WriteLine("A is {0}", calc.number1);
              Console.WriteLine("B is {0}", calc.number2);
              double result = calc.Add();
              Console.WriteLine("A + B = {0}", result);
              result = calc.Subtract();
              Console.WriteLine("A - B = {0}", result);
              result = calc.Multiply();
              Console.WriteLine("A * B = {0}", result);
              Console.WriteLine("Sqrt(A) = {0}", calc.SquareRootNumber1());
              Console.WriteLine("Sqrt(B) = {0}", calc.SquareRootNumber2());
              Console.WriteLine("A = {0}", calc.number1);
              Console.WriteLine("B = {0}", calc.number2);
  
              try
              {
                  result = calc.Divide(); 
                  Console.WriteLine("A / B = {0}", result);
              }
              catch (Exception ex) 
              {
                  Console.WriteLine(ex.Message);
              }
  
              calc.number1=3.14;
              calc.number2=0 ;
              Console.WriteLine("A is {0} ", calc.number1);
              Console.WriteLine("B is {0} ", calc.number2);
              result = calc.Divide();
  
              try { 
                  result = calc.Divide();
                  Console.WriteLine("A / B = {0}", result);
              }
              catch (Exception ex) {
                  Console.WriteLine("The divisor can’t be zero ",ex.Message);
              }
  
              Console.WriteLine("Is memory being used at the beginning? {0}", calc.isMemoryUsed());
              calc.MemoryStore(3.16);
              Console.WriteLine("Is memory being used after MemoryStore? {0}", calc.isMemoryUsed()); 
              Console.WriteLine("Memory = {0}", calc.MemoryRecall());
              calc.MemoryAdd(5.67);
              Console.WriteLine("Is memory being used after MemoryAdd? {0}", calc.isMemoryUsed()); 
              Console.WriteLine("Memory = {0}", calc.MemoryRecall());
              calc.MemorySubtract(7.89);
              Console.WriteLine("Is memory being used after MemorySubtract? {0}", calc.isMemoryUsed());
              Console.WriteLine("Memory = {0}", calc.MemoryRecall());
              calc.MemoryClear();
              Console.WriteLine("Is memory being used after MemoryClear? {0}", calc.isMemoryUsed());
              calc.MemoryAdd(5.67);
              Console.WriteLine("Is memory being used after MemoryAdd? {0}", calc.isMemoryUsed());
              Console.WriteLine("Memory = {0}", calc.MemoryRecall());
              calc.MemoryClear();
              Console.WriteLine("Is memory being used after MemoryClear? {0}",      calc.isMemoryUsed());
              calc.MemorySubtract(7.89);
              Console.WriteLine("Is memory being used after MemorySubtract? {0}", calc.isMemoryUsed()); 
              Console.WriteLine("Memory = {0}", calc.MemoryRecall());
          }
      }
  }
  </code></pre>
  
  <p>THe problem is , i get wrong results:<a href="http://i.stack.imgur.com/vmtKw.png" rel="nofollow">this is my result but the answers must be different!!</a>
  !!!!!! 
  <a href="http://i.stack.imgur.com/DhPe4.png" rel="nofollow">BUT, It should be like this </a>
  there are methods that should have these features:<br>
  Here are some important issues:</p>
  
  <p> The Add() method adds Number1 and Number2 and returns the result back.</p>
  
  <p> The Subtract() method subtracts Number2 from Number1 and returns the result back.</p>
  
  <p> The Multiply() method multiplies Number1 and Number2 and returns the result back.</p>
  
  <p> The Divide() method checks whether Number2 is zero or not. If Number2 is zero, it should throw an Exception with the message “Division cannot be done because Number2 is zero!”. If Number2 is not zero, it should return the division result back.</p>
  
  <p> The SquareRootNumber1() and SquareRootNumber2() methods return the square roots of Number1 and Number2 respectively.</p>
  
  <p> The isMemoryUsed() method should return true if there exists a stored value in the memory of the calculator and false if there is no stored value in the memory.</p>
  
  <p> The MemoryStore(double) method stores the parameter value into the memory.</p>
  
  <p> The MemoryRecall() method returns the value of the memory back. If there is no value stored in the memory, it should return zero.</p>
  
  <p> The MemoryAdd(double) method adds the parameter value into the memory.</p>
  
  <p> The MemorySubtract(double) methods subtracts the parameter value from the memory.</p>
  
  <p> The MemoryClear() method clears the value in the memory.</p>
  
  <p> When MemoryStore, MemoryAdd and MemorySubtract methods are called, a value is stored in the memory and then isMemoryUsed() method should return true. After the MemoryClear() method is called, isMemoryUsed() method should return false. The MemoryRecall() method does not change the value returned by the isMemoryUsed() method.</p>
  
  <p> Your program should give the same output to the program given above.</p>
  
  <p> Carefully specify the member variables and their visibilities (public or private).</p>