Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Javascript 2 decimals force two zeroes if needed 4 47
Problem to Popup 2 52
Default parameter problem in C# 3 27
Wpf develop 5 32
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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

16 Experts available now in Live!

Get 1:1 Help Now