Click here to Skip to main content
15,920,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Me ajuda a resolver este problemas amigo, confesso que não vi uma forma de validar para resolver.

Google Translate:
Help me to solve this problem friend, I confess that I didn't see a way to validate to solve it.


What I have tried:

using System;
using System.Globalization;

namespace _1002
{
    class Program
    {
        static void Main(string[] args)
        {
            double R = Convert.ToDouble(Console.ReadLine());
            double A = Math.PI * Math.Pow(R, R);
            Console.WriteLine("A = " +A.ToString("F4",CultureInfo.InvariantCulture));
           // Console.ReadLine();
        }
    }
}
Posted
Updated 17-Feb-20 20:33pm
v2
Comments
Patrice T 18-Feb-20 1:13am    
English please.

1 solution

You can't "solve" an in put string format problem: it says what it means: the user typed a value that cannot be interpreted as a valid double

You can prevent you app from crashing though:
C#
double R;
while (true)
   {
   Console.Write("Please enter the radius of the circle :"); 
   string input = Console.ReadLine();
   if (double.TryParse(input, out R))
      {
      break;
      }
   Console.WriteLine($"\"{input}\" is not a valid number.");
   }
double A = Math.PI * Math.Pow(R, R);
Console.WriteLine("A = ", A.ToString("F4",CultureInfo.InvariantCulture));
 
Share this answer
 
Comments
Richard Deeming 18-Feb-20 15:18pm    
I can't make it crash, but I can make it output NaN instead of a number! :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900