Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Calculator{
- class MainClass{
- public static void Main (string[] args){
- while (true) {
- int choice;
- string inputNumber;
- double outputNumber;
- double sum = 0;
- bool cont = true;
- bool firstNumber = true;
- Console.WriteLine ("Welcome to my calculator. \nWhich mathematical arithmatic operation do you want to use?");
- Console.WriteLine ("1: Addition (+) \n2: Subtraction (-) \n3: Multiplication (*) \n4: Division (/) \n5: Multiple (+, -, *, /)");
- Console.Write ("\nI want to calculate with: ");
- choice = Convert.ToInt32 (Console.ReadLine ());
- if (choice == 1) {
- Console.Clear ();
- Console.WriteLine ("Input the numbers you want to add. End with '='\n");
- while (cont) {
- Console.Write ("Input: \t");
- inputNumber = Console.ReadLine ();
- cont = Double.TryParse (inputNumber, out outputNumber);
- if (cont) {
- sum = Convert.ToDouble (inputNumber) + sum;
- Console.WriteLine ("+");
- } else {
- if (inputNumber == "=") {
- Console.WriteLine ("Sum = " + sum);
- Console.WriteLine ("\nPress a key to continue");
- sum = 0;
- } else {
- Console.Clear ();
- Console.WriteLine ("Error 150: This is not a valid number. Please contact your administrator.");
- Environment.Exit (0);
- }
- }
- }
- } else if (choice == 2) {//Choice 1 above.
- Console.Clear ();
- Console.WriteLine ("Input the numbers you want to substract. End with '='\n");
- while (cont) {
- Console.Write ("Input: \t");
- inputNumber = Console.ReadLine ();
- cont = Double.TryParse (inputNumber, out outputNumber);
- if (cont) {
- if (firstNumber) {
- sum = Convert.ToDouble (inputNumber);
- Console.WriteLine ("-");
- firstNumber = false;
- } else {
- sum = sum - Convert.ToDouble (inputNumber);
- Console.WriteLine ("-");
- }
- } else {
- if (inputNumber == "=") {
- Console.WriteLine ("Sum = " + sum);
- Console.WriteLine ("\nPress a key to continue");
- sum = 0;
- } else {
- Console.Clear ();
- Console.WriteLine ("Error 150: This is not a valid number. Please contact your administrator.");
- Environment.Exit (0);
- }
- }
- }
- }//Choice 2 above.
- Console.ReadKey ();
- Console.Clear ();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement