Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» ~=?{The future is here, TastyExploit officially open to the public}?=~
Tue Mar 02, 2010 11:00 pm by Dami

» My first aa script
Tue Mar 02, 2010 7:00 am by wafflemaster

» the real story behind Maverin
Tue Mar 02, 2010 1:33 am by SoundOfDeat

» Random spam
Mon Mar 01, 2010 11:52 pm by Danny1994

» [Request] EMS v56 Exe
Mon Mar 01, 2010 12:39 am by Dami

» [Blacklist] NX-Trading Blacklist.
Mon Mar 01, 2010 12:38 am by Danny1994

» I have a question regarding the meso farmer
Sat Feb 27, 2010 10:30 pm by Dami

» What are you listening to now?
Sat Feb 27, 2010 7:57 pm by Noname111111

» Video(s) Of The Day
Sat Feb 27, 2010 7:37 pm by Noname111111

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search
Affiliates
free forum
 



[C#]Creating a Simple Calculator [Source]

Go down

[C#]Creating a Simple Calculator [Source]

Post by Dami on Fri Oct 30, 2009 3:47 am

By Joe

Well lol, i've been reading a book on C# and im only 3 chapters in, but so far i've learnt some pretty basic stuff and i understand things SOOO much easier now, anyway, i think i've made some good progress and this is one of the results of my progress. It's a simple console application wrote in C# and basically adds another number with another number and gives you the product and then just gives you a neat little comment at the end.

This is EXTREMELY basic, and seeing as im really new to C# it might help others out like me who are struggling to learn this language,

Also my IT teacher told me today that we'll be doing a C# for A-Level next year, this made my really happy because then i'll ace it no trouble im sure!

Anyway, here's the code -

Code:

// Basic addition, by Joe.
// Adds two numbers together and gives the total of them.
using System;

public class Addition
{
public static void Main( string[] args )
    {
      int number1; // gets the first number to add 
      int number2; // gets the second number to add
      int sum; // gets the total of the first and second number

      Console.Write( "Enter Your First Number For Addition Please: " ); // comment to user
      // read first number from user
      number1 = Convert.ToInt32( Console.ReadLine() );

      Console.Write( "Enter Your Second Number For Addition Please: " ); // comment to user
      // read second number from user
      number2 = Convert.ToInt32( Console.ReadLine() );

      sum = number1 + number2; // the equation to add the numbers

      Console.WriteLine( "The total is {0}", sum ); // shows the final result
      Console.WriteLine("This Simple Addition Calculator Program Was Written By Joe!\nOf Course This Is Very Basic I Know!");
      Console.Read(); // just gives you time to read the answer and comment
    } // end method Main
} // end class Addition


Ok, so after doing this, i expanded on this simple idea and just tried to experiment, i ended up with this, have a look at it! ZenX helped me with one part when i forgot to add {} for the if statements haha!


Code:

// Basic addition calculator, by Joe.
// Adds two numbers together and gives the total of them.
using System;

public class Addition
{
    public static void Main(string[] args)
    {
        int number1; // gets the first number to add 
        int number2; // gets the second number to add
        int sum; // gets the total of the first and second number

        Console.Write("Welcome to Joe's C# Calculator \n\nIf your first number is bigger than the second \nThen a subtraction will be performed! \n\nHowever if you have a bigger second number compared to first number \nThen the program will perform an addition! \n\nEnjoy! \n"); // instructions to user
        Console.Write(" \nEnter Your First Number For Addition Please: "); // comment to user
        // read first number from user
        number1 = Convert.ToInt32(Console.ReadLine());

        Console.Write("Enter Your Second Number For Addition Please: "); // comment to user
        // read second number from user
        number2 = Convert.ToInt32(Console.ReadLine());
        if (number1 > number2)
        {
            sum = number1 - number2; // the equation to add the numbers
            Console.WriteLine("\nYour subtraction came to {0}", sum); // shows the final result
        }
        if (number1 < number2)
        {
            sum = number1 + number2; // the equation to add the numbers
            Console.WriteLine("\nYour addition came to {0}", sum); // shows the final result
        }
        if (number1 == number2)
        {
            Console.Write("\nHaha, you typed two exact numbers! \nTrying to test me for any flaws or something?!"); // comment to user
        }

        Console.WriteLine(" \n\nThis Simple Addition Calculator Program Was Written By Joe! \n\nOf Course This Is Very Basic I Know!"); // display sum
        Console.Read(); // just gives you time to read the answer and comment
    } // end method Main
} // end class Addition
avatar
Dami
Dragon
Dragon

Posts : 1414
Join date : 2009-08-10
Age : 28
Location : Finland

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum