12,295,252 members (56,213 online)
Articles » Languages » C# » Beginners » Downloads

89K views
7.6K downloads
50 bookmarked
Posted

# Scientific Calculator

, 11 Mar 2008 CPOL
Scientific calculator that calculates fibonacci modulo factorial sin cos tan.. you are able to also change background color and color of the buttons
 Scientific_Calculato Calculator_GUI.suo Calculator_GUI bin Release Calculator_GUI.exe Calculator_GUI.pdb Calculator_GUI.vshost.exe Properties using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace Calculator_GUI { class Operations { private static double result; // create result public Operations() { result = 0; // initialize result to '0' } // addition function public static void add(double num) { if(result == 0) { result = num; // save first number in result } else result += num; // adding second. third.... numbers to result } // subtraction function public static void sub(double num) { if(result == 0) { result = num; // save first number in result } else { result -= num; } } // starting with minus ex: -3-3 public static void Ssub(double num) { if(result == 0) { result = num; // save first number in result } else { result -= num; } } // multiplication method public static void mult(double num) { if(result == 0) { result = num; // save first number in result } else result *= num; } // division method public static void div(double num) { if (result != 0 && num == 0) { MessageBox.Show("Cannot divide by 0"); } if(result == 0) { result = num; // save first number in result } else result /= num; } // sin method public static void sin(double num) { if(result == 0) { result = Math.Sin(num); } else result = Math.Sin(result); } // cos method public static void cos(double num) { if(result == 0) { result = Math.Cos(num); } else result = Math.Cos(result); } // tan method public static void tan(double num) { if(result == 0) { result = Math.Tan(num); } else result = Math.Tan(result); } // square root method public static void sqrt(double num) { if(result == 0) { result = Math.Sqrt(num); } else result = Math.Sqrt(result); } // modulus method public static void modulo(double num) { if(result == 0) { result = num; } else { result %= num; } } // square method public static void square(double num) { result = num * num; } // cube method public static void cube(double num) { result = num * num * num; } // factorial method public static long factorial(long num) { if(num >= 21 || num < 0) { MessageBox.Show("Enter number between 0 & 20", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return 0; } else { if(num <= 1) return 1; else return num * factorial(num - 1); // recursive function } } // fibonacci method public static long fibonacci(long num) { if(num >= 40 || num < 0) { MessageBox.Show("Enter number between 0 & 40", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return 0; } else { if(num == 0 || num == 1) return num; else return fibonacci(num - 1) + fibonacci(num - 2); } } public static void clear() { result = 0; // clear result } public static double getResult() { return result; // get result } } // end class Operations } // end namespace Calculator_GUI

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 Software Developer Liberia
No Biography provided

## You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 11 Mar 2008
Article Copyright 2008 by Ramzi987654321
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid