Solved

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

Posted on 2008-10-24
5
278 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
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now