Hey guys, just wanted to drop in a very simple app which I have made for you, seeing the fact that we have enough information already till now to actually combine all our skills we have learned till now and build an app.

It is just a very simple calculator which I have built for you guys to kinda refresh up your mind to what we have covered till now.

Suggested Reading :

Do take a look and you are welcome to make your own improvements to the code and design, which would be really good for you.

1. Now as we know, there are the four basic operations that a calculator can do- add, subtract, multiply and divide. Just to make things interesting and improve the functionality a little bit, I have used the modulus operation too.

2. As I said, it is a really simple code and design, you should not have any problems building this app, but let me assure you that if you do this successfully. it is going to give a major boost to your confidence.

3. The design of the app will be something like this-

I have used a symbol (i.e. +,-,/,* and %) to represent each of the operations. Now do take in note that the symbols each consist of a button each, so that makes it 5 buttons which I have imported from the ToolBox. Each is going to perform a unique operation.

4. When this is done, double click each of the buttons and write down the code as shown below (I have shown you the whole app code, try figuring out which one belongs to which button)-

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
using System.Net;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Animation;
usingSystem.Windows.Shapes;
usingMicrosoft.Phone.Controls;

namespace Variables
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
publicMainPage()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
int val1 = 0;
int val2 = 0;

val1 = int.Parse(textBox1.Text);
val2 = int.Parse(textBox2.Text);

textBlock1.Text = (val1 + val2).ToString();
}

private void button2_Click(object sender, RoutedEventArgs e)
{
int val1 = 0;
int val2 = 0;

val1 = int.Parse(textBox1.Text);
val2 = int.Parse(textBox2.Text);
textBlock1.Text = (val1 – val2).ToString();
}

private void button3_Click(object sender, RoutedEventArgs e)
{
int val1 = 0;
int val2 = 0;

val1 = int.Parse(textBox1.Text);
val2 = int.Parse(textBox2.Text);
textBlock1.Text = (val1 / val2).ToString();
}

private void button4_Click(object sender, RoutedEventArgs e)
{
int val1 = 0;
int val2 = 0;

val1 = int.Parse(textBox1.Text);
val2 = int.Parse(textBox2.Text);
textBlock1.Text = (val1 * val2).ToString();
}

private void button5_Click(object sender, RoutedEventArgs e)
{
int val1 = 0;
int val2 = 0;

val1 = int.Parse(textBox1.Text);
val2 = int.Parse(textBox2.Text);
textBlock1.Text = (val1 % val2).ToString();
}

}
}

5. Do note that I have used Parse() in order to convert the int to a String data-type explicitly, as the int data-type cannot be converted to String, which is the native data-type that the textBox can get as input and the textBlock can display.

6. When I run this code this will give us an output which looks like this-

This should give the correct output for each of the button symbols pressed. So try doing the other buttons and happy coding!

Achievement-use this calculator for your daily simple calculation needs and you will be really satisfied.

Do you like this post?

About

Shathyan Raja is a Blogger and Content Writer at various Blogs namely Zlobber.com and Techulator.com. Check out and contact him via Facebook Profile or Google+ Profile. He is the founder of Samsung Galaxy S 4 were you can find all updates on this upcoming smartphone.

Comments:
  1. Amanda@BuySellWordPress

    It seems to be a little bit difficult for me. But maybe I will try to check it out. Thanks for this instruction

  2. Trip to India

    This is the benefit of new technology which helps lot more for anyone specially for those who wants to feel something unique after sometime.

  3. chicharito

    thanx they really helped me but
    int val1 = 0;
    int val2 = 0;
    you should make them available to all methods but putting them just below you constructor

  4. Melissa

    “Happy coding!” sounds very encouraging!)) I will try to check it ) Thanks for such a detailed instruction

  5. Gowtham

    Good Post ! Seems you are good at coding. Do you know how to create app for websites in Windows 7 ?

  6. Bhagya රාජපක්ෂ

    Big Thanks.. It helped me alot when I was making a Shape Calculator which gets length, width, height and outputs Area, Volume, Circumference of both 2D and 3D shapes :)

Leave a Reply

(required)

(required)


Copyright © 2008-2012 Comptalks - All Rights Reserved.