Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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