Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
Using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            //Variables needed
            double a, b, X;
            //Printing the message and taking input a
            Console.WriteLine("Enter the value for a: ");
            a = double.Parse(Console.ReadLine());
            //Printing message and taking input b
            Console.WriteLine("Enter the value for b: ");
            b = double.Parse(Console.ReadLine());
            //Taking the degree value of the BETA
            Console.WriteLine("Enter the value for BETA: ");
            int beta =  int.Parse(Console.ReadLine());
            //Converting into radian by muliplying with PI/180
            double betaRad = beta * (Math.PI / 180);
            //Calculating the numerator of the FORMULA
            double num = (3 * a) + b;
            //Calculating denomenator of the formula
            double denom = Math.Sqrt(a * a * Math.Pow(Math.Sin(betaRad), 2)) - (b * b * Math.Cos(betaRad));
            X = num / denom;
            //Printing the result ROUNDED to two places
            Console.WriteLine(Math.Round(X,2));
        }
    }
}


What I have tried:

I have tried looking up everything
Posted
Updated 6-Feb-21 11:08am
v2
Comments
[no name] 6-Feb-21 16:20pm    
Maybe because it is c# code and not Python.

In addition to what Dave and Patrice have said - C# is case sensitive - the Main method in a Console app must be public, as must the class that contains it.
Try:
C#
using System;

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Variables needed
            double a, b, X;
            //Printing the message and taking input a
            Console.WriteLine("Enter the value for a: ");
            a = double.Parse(Console.ReadLine());
            //Printing message and taking input b
            Console.WriteLine("Enter the value for b: ");
            b = double.Parse(Console.ReadLine());
            //Taking the degree value of the BETA
            Console.WriteLine("Enter the value for BETA: ");
            int beta =  int.Parse(Console.ReadLine());
            //Converting into radian by muliplying with PI/180
            double betaRad = beta * (Math.PI / 180);
            //Calculating the numerator of the FORMULA
            double num = (3 * a) + b;
            //Calculating denomenator of the formula
            double denom = Math.Sqrt(a * a * Math.Pow(Math.Sin(betaRad), 2)) - (b * b * Math.Cos(betaRad));
            X = num / denom;
            //Printing the result ROUNDED to two places
            Console.WriteLine(Math.Round(X,2));
        }
    }
}
But please, dump the comments. They are useless because they tell us what the code is doing, not why it's doing it. If your comment doesn't add to understanding, it's not worth keeping - in fact it's misleading, as it's unlikely to modified when the code is.
About the only partially useful comment in there is this one:
C#
//Converting into radian by muliplying with PI/180
double betaRad = beta * (Math.PI / 180);
And that could be replaced by improving the variable name:
C#
double radiansBeta = beta * (Math.PI / 180);
 
Share this answer
 
Comments
Dave Kreskowiak 6-Feb-21 18:51pm    
Nice catch.
Quote:
I have tried looking up everything

Did you tried lowercase ?
C#
using System;
 
Share this answer
 
C# is case sensitive.

Change "Using" to "using".
 
Share this answer
 
Comments
Member 15066444 6-Feb-21 16:46pm    
Still won’t run

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



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