YAY! Joy, read inside!

dsfreak

New Member
Messages
1,338
Reaction score
0
Points
0
Hey, guess what? I just made my first C# application. I know, you may think first? WOW, I have made like 1000..... Well, I would probably have more if I happened to have had my computer the past few months. Anyhow, it is just a basic program, that I named SIMPLE Calculator. I would like someone (or more) to downlaod it and tell me if I did a good job on my first C# program...... Btw, next up on the line for me is a SIMPLE Web-Browser.


Thanks!

File: Simple Calculator Setup
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
If you want anyone to actually run it, post the source also.

Anyways, good job. I recently have been working on learn C++. Although not C, they have a few things in common.
 

dsfreak

New Member
Messages
1,338
Reaction score
0
Points
0
Ok, I will edit this with the source. I can see that someone might think there is a virus attached, so, here you go:


Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            float firstNumber = float.Parse(txtFirstNumber.Text);
            float secondNumber = float.Parse(txtSecondNumber.Text);
            float result = firstNumber + secondNumber;
            lbResult.Text = "The anwser is: " + result.ToString();
        }

        private void btnSubtract_Click(object sender, EventArgs e)
        {
            float firstNumber = float.Parse(txtFirstNumber.Text);
            float secondNumber = float.Parse(txtSecondNumber.Text);
            float result = firstNumber - secondNumber;
            lbResult.Text = "The anwser is: " + result.ToString();
        }

        private void btnDivide_Click(object sender, EventArgs e)
        {
            float firstNumber = float.Parse(txtFirstNumber.Text);
            float secondNumber = float.Parse(txtSecondNumber.Text);
            float result = firstNumber / secondNumber;
            lbResult.Text = "The anwser is: " + result.ToString();
        }

        private void btnMultiply_Click(object sender, EventArgs e)
        {
            float firstNumber = float.Parse(txtFirstNumber.Text);
            float secondNumber = float.Parse(txtSecondNumber.Text);
            float result = firstNumber * secondNumber;
            lbResult.Text = "The anwser is: " + result.ToString();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtFirstNumber.Text = "Cleared!";
            txtSecondNumber.Text = "Cleared!";
            lbResult.Text = "Result: All fields cleared!";
        }
    }
}

Edit: This code is released under the GNU Public License. Any attempt to edit and/or republish as your own, or without a refrence back to the author is strictly prohibited.
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
Cool, good job.

What kind of application is that? A windows app, console app, etc.. When I try to compile it, I get an error for the "Using System.[Blah]" parts... I don't knowww..

Do you know any C++?

I just made this Friday, it's pretty much the same thing, so I feel like sharing it with you/everyone:

Code:
#include <iostream>

class Calculator {
      public:
      int x;
      int y;
      int result;
      int choice;
            
      Calculator();
      void makeChoice();
      void getNumbers();
      void doMath();
      int getResults();
     
};

Calculator::Calculator() {
  x = 0;
  y = 0;
  choice = 0;                      
}



void Calculator::makeChoice() {
    std::cout<< "Which of the following would you like to do? Choose a number." << std::endl;
    std::cout<< "(1) Addition" << std::endl;
    std::cout<< "(2) Subtraction" << std::endl;
    std::cout<< "(3) Multiplication" << std::endl;   
    std::cout<< "(4) Divison" << std::endl;
    std::cout<< "Choice: ";
    std::cin>> choice;
}


void Calculator::getNumbers() {
    std::cout<< "Enter first integer: ";
    std::cin>> x;
    std::cin.ignore();
    std::cout<< "Enter second integer: ";
    std::cin>> y;
    std::cin.ignore();
    std::cout<< "\n    First Number: " << x << std::endl;
    std::cout<< "    Second Number: " << y << "\n" << std::endl;
}

void Calculator::doMath() {
    switch(choice) {
      case 1:
      result = (x + y);
      break;
     
      case 2:
      result = (x - y);
      break;
     
      case 3:
      result = (x * y);
      break;
     
      case 4:
      result = (x / y);
      break;
    }
}

int Calculator::getResults() {
  return result;
}

int main() {
    Calculator calc;
    std::string ynstring;
do
{
    calc.makeChoice();
    calc.getNumbers();
    calc.doMath();
    std::cout<< "Result: " << calc.getResults();
    std::cin.get();
    std::cout << "Do another? Yes|No ";
    std::cin>> ynstring;
    std::cout << "\n";
}
while(ynstring != "No" && ynstring == "Yes");
    return 0;
}
 

dsfreak

New Member
Messages
1,338
Reaction score
0
Points
0
This is C# code. Also, it is a Windows Application, and needs .NET framework 2.0 BETA (or w/e it is) to run. This is because I am using the free express edition from Microsoft. Unfortunately, since this is only my second acquired code knowledge, I don't know C++, but I heard that they were rather similar.
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
Ahh I see, that's why I couldn't compile it, I don't have the .net framework 2 shiz. Hmm.
 

dsfreak

New Member
Messages
1,338
Reaction score
0
Points
0
You can download it in like 2-3 minutes from Microsoft. Search Microsoft.com for it. ;-)
 

MicrotechXP

New Member
Messages
7,644
Reaction score
0
Points
0
Thats nice but I can not download it. It says your account was suspended.
 
Top