CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Posts
    12

    Having an issue with code

    I have been working on a problem, but it doesn't work and I'm stuck. Any hints or ideas would be a huge help!!! The program is supposed to display a menu to compute the area of a triangle, circle, cylinder. Someone already helped me a bit but Im not sure if they were right, especially since it doesn't work.


    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    {
    int choice = 0;
    Console.WriteLine("[1]Area of a Circle");
    Console.WriteLine("[2]Area of a Rectangle");
    Console.WriteLine("[3]Area of a Cylinder");
    choice = int.Parse(Console.ReadLine());


    if (choice == 1)
    {
    AreaCir();
    TryAgain();
    }

    }

    private static void TryAgain()
    {
    string yorn;
    Console.WriteLine("Do you want to try again?[Y/N]");
    yorn = Console.ReadLine();

    if (yorn == "y" || yorn == "Y")
    {
    int choice = 0;
    Console.WriteLine("[1]Area of a Circle");
    Console.WriteLine("[2]Area of a Rectangle");
    Console.WriteLine("[3]Area of a Cylinder");
    choice = int.Parse(Console.ReadLine());
    if (choice == 1)
    {
    AreaCir();
    TryAgain();
    }
    }
    else
    {
    Console.WriteLine("Thank you for using this program!");
    }


    }

    private static void AreaCir()
    {
    double areacir, radius, pi = 3.14;
    Console.WriteLine("Enter a value for radius: ");
    radius = double.Parse(Console.ReadLine());
    areacir = pi * radius * radius;

    Console.WriteLine("Area of a circle is: " + areacir);

    }
    }
    }

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Having an issue with code

    Despite it is wrong in design because there should be loop, not a recursion, in which sense it doesn't work?
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured