?
Solved

Building Simple calculator...error message: CLASS, STRUCT, OR INTERFACE MUST HAVE RETURN TYPE

Posted on 2008-10-24
5
Medium Priority
?
284 Views
Last Modified: 2013-12-17
I am trying to create a simple calculator in Visual Studio 2005  the inerface has 2 textboxes fro input one and two.  Then a button to add two values.  I keep getting an error.  I am not even sure that i am reading tinot the textbox correctly.  Please see below for error...

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 button1_Click(object sender, EventArgs e)
        {
           
        }

        public  calculator()
        {
            int total;
            int txtbox1;
            int txtbox2;

            total = txtbox1 + txtbox2;

            label3 = Console.WriteLine(total) ;

        }
    }
}
0
Comment
Question by:GlobaLevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22803123
label3.Text = Console.WriteLine(total) ;
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 22803882
I tried running it with your suggestion..I still got the same error as listed above...I dont think it likes the way I declared the method--public calculator()...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22803971
And, here I first though that was the constructor for a class, and it was method in a form (d'oh).

 public int calculator()
        {
            int total;
            int txtbox1;
            int txtbox2;

            total = txtbox1 + txtbox2;

            label3.Text = total.ToString();

        }
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 22805144
I copied and pasted your code into my program and I got a 'use of unassigned local variable error' now...and a not all code paths return a value...
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 22807271
public int Add(int value1, int value2)
 {
     return value1 + value2;
 }

 public int Subtract(int value1, int value2)
 {
     return value1 - value2;
 }

 public int Multiply(int value1, int value2)
 {
     return value1 * value2;
 }

 public double Divide(int value1, int value2)
 {
     return (double)(value1 / value2);
 }
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question