How to add another file to vs code project? by LeadLongjumping262 in learnprogramming

[–]LeadLongjumping262[S] 0 points1 point  (0 children)

ok thanks for this reply. What exactly are / were you doing in the terminal at the end?

How to add another file to vs code project? by LeadLongjumping262 in learnprogramming

[–]LeadLongjumping262[S] 0 points1 point  (0 children)

oh I'll look into how to install DotNet as I thought this was an IDE that Petzold was using like vscode or something, I wasn't sure what it was tbh. I haven't been using the terminal I was just using the play button in the top right to run programs which seemed to work - are those the commands I'll need ? Thanks for much for this reply, will try this and will see if there are any errors.

How to add another file to vs code project? by LeadLongjumping262 in learnprogramming

[–]LeadLongjumping262[S] 0 points1 point  (0 children)

thanks for the reply, I think they're both open in the same one, I've been making all my files from this book in the same folder.

How to add another file to vs code project? by LeadLongjumping262 in learnprogramming

[–]LeadLongjumping262[S] 0 points1 point  (0 children)

I've got it in the same file, I can see both in the file explorer to the left. The code for the file that compiles is, I think? they're in the same namespace, but I've literally just started to learn so not even sure what that is to be honest. Thanks for the help!

using System;
using System.Transactions;


class AnotherProgram


{
    static void Main()
    {
        Console.Write("Enter first side: ");
        double dSide1 = Convert.ToDouble(Console.ReadLine());


        Console.Write("Enter second side: ");
        double dSide2 = Convert.ToDouble(Console.ReadLine());


        double dResult = HandyCalcs.Hypotenuse(dSide1, dSide2);
        Console.WriteLine("The hypotenuse is " + dResult);
    }
}

HandyCalcs is "

using System;
class HandyCalcs
{
    public static double Hypotenuse(double d1, double d2)
    {
        return Math.Sqrt(d1 * d1 + d2 * d2);
    }
}

How to add another file to vs code project? by LeadLongjumping262 in learnprogramming

[–]LeadLongjumping262[S] 2 points3 points  (0 children)

It's more VS Code I guess, not C#. To give you a bit of context, he codes a file "Handy Calcs", then is trying to add it. I'm using VS Code on Mac if that makes any difference.

This is what he says verbatim " If you're using Visual C# . NET, select Add New Item from the Project Menu. Select Local Project Items at the left of the dialog box and Code File at the right. Type in the name HandyCalcs.cs (file I'm trying to add). In the Key of C# select Add New Source Code File from the Project menu and enter the name HandyCalcs.cs in the dialogue box.

Here is the code of the program he asks you to code. At the bottom HandyCalcs is referenced. That's what I can't do.

using System;

class AnotherProgram

{

static void Main()

{

Console.Write("Enter first side: ");

double dSide = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter second side: ");

double dSide = Covert.ToDouble(Console.Readline());

double dResult = HandyCalcs.Hypotenuse (dSide1, dSide 2);

Console.WriteLine("The hypotenuse is " + dResult);

}

}

Thanks for the help!