Wrox Programmer Forums
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 29th, 2005, 05:03 PM
Authorized User
Join Date: Jul 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# newbie

Hello and thank you for taking a moment to read this message. I am new to C# and am just working through some exercises in a book I just purchased. The exercise I am having trouble with askes me to do the following:

Create a class named TestCircle whose Main() method declares three class Circle objects. Using a SetRadius() method from the more general Circle class, assign a small radius value to one circle, assign a larger radius to another Circle. Do not assign a value to the radius of a third circle; instead, retain a value assigned at construction. Call ComputeDiameter() and ComputeArea() for each circle and display the results.

Here is my code:

using System;
class Circle
public int Radius =1;
private int Diameter;
private double Area;

/*Here are your Set Methods for this class*/
    public int SetRadius(int r)
    Radius= r;

/*Here are your Get Methods for this class*/

public int GetRadius()
     return Radius;
public int GetDiameter()
    return Diameter;

public double GetArea()
     return Area;
/*Here are your Compute Methods for this class*/

public int ComputeDiameter()

public double ComputeArea()
    Area =(radius*radius)* 3.14;
public class TestCircle
public static void Main()
Circle firstCircle =new Circle();

Console.Writeline("My first circle has a diameter of {0} and a an area of{1}",firstCircle.GetDiameter(), firstCircle.GetArea());

Circle secondCircle= new Circle();
Console.Writeline("My second circle has a diameter of {0} and a an area of{1}",secondCircle.GetDiameter(), thirdCircle.GetArea());

Circle thirdCircle= new Circle();
Console.Writeline("My third circle has a diameter of {0} and a an area of{1}",thirdCircle.GetDiameter(), thirdCircle.GetArea());
Visual Studio Gives me the following Errors:

  'Circle.SetRadius(int)': not all code paths return a value
  ' The left-hand side of an assignment must be a variable, property or indexer
  'Circle.ComputeArea()': not all code paths return a value

Any help would be greatly appreciated. - Jason

Old November 29th, 2005, 06:03 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma

public int SetRadius(int r)

public void SetRadius(int r)
and add this line

return Area;
as the last line in ComputeArea()

U r posting very basic stuff so once you are through, think why are u or were you getting these errors. There may be some more errors waiting but if you know "why" you would be able to solve the problems yourself. Read your book carefully.

Ankur Verma

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help the newbie!! shelly.aix Visual Basic 2008 Essentials 2 December 16th, 2008 07:35 AM
Newbie help... mkruger XSLT 7 October 24th, 2007 02:33 AM
Newbie here jmac731976 HTML Code Clinic 13 August 29th, 2007 03:54 PM
Newbie please help indyanguy XSLT 1 September 2nd, 2005 09:18 AM
Newbie Help! TheShadow Javascript 1 March 21st, 2005 03:42 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.