CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jun 2014
    Posts
    17

    Lightbulb C# Console App - Error Check Calculator [Finished]

    Just came back with a finishing update on the error check calculator. Feel free to use the code below or to use as a reference. By the way if anyone can shorten my prototype programming with arrays or anything, share the knowledge, any at all is appreciated.

    Code:
    static void Main()
            {
                string first_input;
                string second_input;
                float inputvalue1 = 0f;
                float inputvalue2 = 0f;
                bool exc1 = true;
                bool exc2 = true;
    
                Console.WriteLine("<This Is A Calulator That Takes 2 Numbered Inputs, Real Or Rational>");
                Console.WriteLine("<It Also Checks If A User Entered A Correct Input>");
                Console.WriteLine("<Press Enter After Entering A Number To Proceed Calculation>");
                Console.WriteLine("\n");
    
                while (exc1)
                {
                    Console.WriteLine("Enter A Number:");
                    first_input = Console.ReadLine();
    
                    if (true == float.TryParse(first_input, out inputvalue1))
                    {
                        exc1 = false;
                    }
                    else
                    {
                        exc1 = true;
                        Console.WriteLine("Error --> You Did Not Enter The First Number Correctly! Try Again");
                        Console.WriteLine("\n");
                    }
                }
    
                while (exc2)
                {
                    Console.WriteLine("Enter The Second Number:");
                    second_input = Console.ReadLine();
    
                    if (true == float.TryParse(second_input, out inputvalue2))
                    {
                        exc2 = false;
                        Console.WriteLine("\n");
                    }
                    else
                    {
                        exc2 = true;
                        Console.WriteLine("Error --> You Did Not Enter The Second Number Correctly! Try Again");
                        Console.WriteLine("\n");
                    }
                }
    
                Console.WriteLine("The 4 Basic Operations Calulate Your Numbers Out As:");
                Console.WriteLine(inputvalue1 * inputvalue2 + " = " + inputvalue1 + " * " + inputvalue2 + " <Multiplied>");
                Console.WriteLine(inputvalue1 / inputvalue2 + " = " + inputvalue1 + " / " + inputvalue2 + " <Divided>");
                Console.WriteLine(inputvalue1 + inputvalue2 + " = " + inputvalue1 + " + " + inputvalue2 + " <Added>");
                Console.WriteLine(inputvalue1 - inputvalue2 + " = " + inputvalue1 + " - " + inputvalue2 + " <Subtracted>");
                Console.WriteLine("\n");
    
                Console.WriteLine("<Press Enter To End Program>");
                Console.Read();
            }
    Last edited by Dylan3dx; July 18th, 2014 at 04:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured