locked
c# beginner RRS feed

  • Question

  • You need to create a lambda term to calculate the surface of a circle. A lambda expression is provided with a radius of the circle, while the lambda expression needs to produce a text message (string) that will contain the result. help
    Sunday, December 9, 2018 6:44 PM

Answers

  • You need to create a lambda term to calculate the surface of a circle. A lambda expression is provided with a radius of the circle, while the lambda expression needs to produce a text message (string) that will contain the result. help

    I also don't know what is this "lambda expression needs to produce" thing is

    I just took the code from  the link provided by Wendy Zang and made a simple change

      
          static  string CalculateArea(int radius)=> $"The Area of circle of given radius is: {3.14 * Math.Pow(radius, 2)}";
    
     static void Main(string[] args)
            {
    
                 int r;
               
                Console.WriteLine("Enter the radius:");
                r = Convert.ToInt32(Console.ReadLine());
             
                Console.WriteLine(CalculateArea(r));
               
                 Console.ReadKey();
            }

    I think you wanted to use lambda lol


    BP-LP 2005/2016 @ll rights reserved

    • Marked as answer by JasminArtz Thursday, December 13, 2018 4:12 PM
    Tuesday, December 11, 2018 10:16 AM

All replies

  • Hi JasminArtz,

    Thank you for posting here.

    For your question, if you want to calculate the surface of a circle, you could try the code in the link below.

    https://forgetcode.com/csharp/1514-area-of-circle

    But, what does this “the lambda expression needs to produce a text message (string) that will contain the result” mean? Please provide more information.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Wednesday, December 12, 2018 8:49 AM
    Monday, December 10, 2018 2:21 AM
  • You need to create a lambda term to calculate the surface of a circle. A lambda expression is provided with a radius of the circle, while the lambda expression needs to produce a text message (string) that will contain the result. help

    I also don't know what is this "lambda expression needs to produce" thing is

    I just took the code from  the link provided by Wendy Zang and made a simple change

      
          static  string CalculateArea(int radius)=> $"The Area of circle of given radius is: {3.14 * Math.Pow(radius, 2)}";
    
     static void Main(string[] args)
            {
    
                 int r;
               
                Console.WriteLine("Enter the radius:");
                r = Convert.ToInt32(Console.ReadLine());
             
                Console.WriteLine(CalculateArea(r));
               
                 Console.ReadKey();
            }

    I think you wanted to use lambda lol


    BP-LP 2005/2016 @ll rights reserved

    • Marked as answer by JasminArtz Thursday, December 13, 2018 4:12 PM
    Tuesday, December 11, 2018 10:16 AM
  • I notice that.

    I think that is ok to post homework, as long as he wants to learn :) 

    BP-LP 2005/2016 @ll rights reserved

    Tuesday, December 11, 2018 1:19 PM
  • Seeing things this way, you're 100% right.


    BP-LP 2005-2016 @ll rights reserved

    BP-LP 2016-2018 @ll rights reserved


    Tuesday, December 11, 2018 1:34 PM
  • thank you very much. also, can you tell me can i use tryparse instead convert?
    Thursday, December 13, 2018 4:14 PM
  • i did it :D

    static string CalculateArea(double radius) => $"The Area of circle of given radius is: {Math.PI * Math.Pow(radius, 2)}";
            static void Main(string[] args)
            {
                string s;
                string novoRacunanje = "ne";
                do
                {
                    bool ispravanUnos = false;
                    while (!ispravanUnos)
                    {
                        double rs;
                        Console.WriteLine("Enter the radius:");
                        s = Console.ReadLine();
                        ispravanUnos = double.TryParse(s, out double y);
                        if (ispravanUnos)
                        {
                            rs = y;
                            Console.WriteLine(CalculateArea(rs));
                        }
                        else
                        {
                            Console.WriteLine("Neispravan unos");
                        }
                    }
                    Console.WriteLine("try again? Y/N?");
                    novoRacunanje = Console.ReadLine();
                } while (novoRacunanje=="Y" || novoRacunanje=="y");
            }

    Thursday, December 13, 2018 6:07 PM
  • Yes, you can.

    As you already figured out :) 

    BP-LP 2005/2016 @ll rights reserved

    Friday, December 14, 2018 7:16 AM
  • not accepted, i failed. need to use delegate?!?
    Friday, December 14, 2018 12:54 PM






  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;



        delegate double circle(double PI);

        class Program
        {
            static void Main(string[] args)
            {
              
                Console.WriteLine("Enter the radius: ");
                circle x = (double PI) =>
                {
                    double r;
                    r = Convert.ToInt32(Console.ReadLine());
                    return PI * r * r;
                };
                Console.WriteLine("The Area of circle of given radius is = {0}", x(3.14));
                Console.Read();
            }
        }












    • Proposed as answer by vabraun Wednesday, January 9, 2019 5:21 PM
    Wednesday, January 9, 2019 5:21 PM