Solved

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

Posted on 2008-10-24
5
283 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

705 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