Find the error(s) in the following code, which should take an int value as an argu- ment and return the value of that argument multiplied by two.


int TimesTwo( int intNumber )
{
int intResult;

intResult = intNumber * 2;

} // end method TimesTwo


A non-void method should return a value. If you do not include a return state-

ment, it is a syntax error. The complete incorrect code reads:





// Double.cs (Incorrect)



using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace Double

{

///

/// Summary description for FrmDouble.

///


public class FrmDouble : System.Windows.Forms.Form

{

private System.Windows.Forms.Button btnDouble;

private System.Windows.Forms.TextBox txtInput;

private System.Windows.Forms.Label lblDoubled;

private System.Windows.Forms.Label lblDoubledText;

private System.Windows.Forms.Label lblInputText;

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;



public FrmDouble()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent

// call

//

}



///

/// Clean up any resources being used.

///


protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}



// Windows Form Designer generated code



///

/// The main entry point for the application.

///


[STAThread]

static void Main()

{

Application.Run( new FrmDouble() );

}



// prints the result of helper method TimesTwo

private void btnDouble_Click(

object sender, System.EventArgs e )

{

int intInputNumber;



intInputNumber = Int32.Parse( txtInput.Text );



lblDoubled.Text =

Convert.ToString( TimesTwo( intInputNumber ) );



} // end method btnDouble_Click

// returns the input multiplied by 2

int TimesTwo( int intNumber )

{

int intResult;



intResult = intNumber * 2;

There is no return

statement in the method

} // end method TimesTwo



} // end class FrmDouble

}



Computer Science & Information Technology

You might also like to view...

Which of the following is true about database backup types?

A. backups can be performed when a database is offline B. backups cannot be performed when a database is online C. SQL Server 2012 databases can only be backed up using Object Explorer D. incremental backups can be performed using the BackUp Database dialog box

Computer Science & Information Technology

C++ provides two types of address parameters: ____________________ and pointers.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

A value or expression that can be evaluated as true or false is called a logical test

Indicate whether the statement is true or false

Computer Science & Information Technology

The ____________________ refers to which data you would edit if you started typing.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology