Search This Blog

Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Tuesday, 5 April 2016

QUADRATIC EQUATION ROOT CALCULATOR WITH COMPLEX ROOT ON VISUAL BASIC Part 2 (FORM)

Ok guys, here is the second part of the quadractic equation solver but here it is created on windows form (having GUI).

Ok here is the code for the form........

Public Class Form1
    Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
        Try

            Dim a = Convert.ToDouble(textBox1.Text)
            Dim b = Convert.ToDouble(textBox2.Text)
            Dim c = Convert.ToDouble(textBox3.Text)
            Dim x1 As Double, x2 As Double, d As Double
            Dim eg As Double = Math.Pow(b, 2) - (4 * a * c)
            If eg > 0 Then
                d = Math.Sqrt(eg)
                x1 = (-b + eg) / (2 * a)
                x2 = (-b - eg) / (2 * a)
                label6.Text = "Real roots: x1 = " + x1.ToString() + ", x2 = " + x2.ToString()
            ElseIf eg = 0 Then
                x1 = -b / 2
                label6.Text = "Equal roots: x1 = " + x1.ToString() + ", x2 = " + x1.ToString()
            Else : d = Math.Round(Math.Sqrt(-1 * eg) / 2, 2)
                x1 = -b / 2
                label6.Text = "Complex roots: x1 = " + x1.ToString() + " + i" + d.ToString() + "     x2 = " + x1.ToString() + " - i" + d.ToString()
            End If

        Catch ex As Exception
            MessageBox.Show("Invalid Input", "Error")
        End Try
    End Sub
End Class

Here is the Output



Video Output

Thanks for Reading...

Monday, 14 December 2015

Bird in Trouble Game in C#

Hello Guys, Check out the demo of the new game i made in c# titled

BIRD IN YAWAH




check the demo video


Also check this out


Download game here and files from here (Bird_In_Trouble.zip)


I will show you guys later on how to make the game from scratch. Keep visiting this blog for more.
Bye

Thursday, 6 August 2015

CREATE A SIMPLE SIMULTANEOUS EQUATION CALCULATOR WITH C#


Hello guys first what is a simultaneous equation: This involves the calculation of more than one equation with unknowns simultaneously.








Back to c-sharp programming, first you need to solve the equation in terms of its constants as shown below

































Just like a pseudocode…..


Here is the code


using System;

namespace Simultaneous_Equation
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Simultaneous Equation Solver");
//prints the message in the quote
            string choice;
            do
            {

/*(multi line comment) a do loop= runs the code in the block and then checks if the condition in the while loop is met to run again else it breaks out of the loop*/

                try
                {
//try and catch looks for exception and the catches it, the prints the //message in the catch block.
                    Console.WriteLine("Input in the format Ax + By = C");
                    Console.Write("x1= ");
                    int A = int.Parse(Console.ReadLine());
                    Console.Write("y1= ");
                    int B = int.Parse(Console.ReadLine());
                    Console.Write("c1= ");
                    int C = int.Parse(Console.ReadLine());
                    Console.Write("x2= ");
                    int D = int.Parse(Console.ReadLine());
                    Console.Write("y2= ");
                    int E = int.Parse(Console.ReadLine());
                    Console.Write("c2= ");
                    int F = int.Parse(Console.ReadLine());
                    float x, y;
// equate the variable in terms of the constant
                    y = ((A * F) - (C * D)) / ((A * E) - (B * D));
                    if (A == 0) { x = (F - (E * y)) / D; }
                    else { x = (C - (B * y)) / A; }
                    Console.WriteLine("The value of x = {0}\nThe value of y = {1}", x, y);
                }
                catch { Console.WriteLine("Input is either wrong or not a simultaneous equation"); }
                Console.WriteLine(" TRY AGAIN?? Type yes else quit");
                choice = Console.ReadLine().ToLower();
            } while (choice == "yes");
            Console.ReadKey(true);
        }
    }
}





Try with many other equations or visit me  here or on youtube for more