C
C#2mo ago
Chicken

✅ How do i print the number difference between 2 numbers like i have 4 and 5

and i want it to say a difference of 1 ya know
5 Replies
Angius
Angius2mo ago
Well, you can use - to subtract one from the other Then use Console.WriteLine() to print the result
Rex_rawr
Rex_rawr2mo ago
And if you want it to be only positive numbers you could also use Math.Abs() to get the absolute value
ɢʟᴀᴢ_ᴀʟᴍᴀᴢ
c#
int a = 5
int b = 4
int result = a - b
Console.WriteLine(result.ToString());
c#
int a = 5
int b = 4
int result = a - b
Console.WriteLine(result.ToString());
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Cali_West
Cali_West5w ago
I'm just guessing here but maybe you're not talking about the code so much as the environment setup? I know that can be kind of frustrating at first. If you want to just be able to run your code on your local machine, open a PowerShell terminal and enter the following commands:
# Make sure you're in your home directory first or somewhere where you won't run into permissions problems:
cd
# This creates a project with the name "MyTest":
dotnet new console -n 'MyTest'
# but it creates it in its own directory. So change into that dir:
cd MyTest
# in here you can use the dir command to see the files it made:
dir
# which should list at least these two files:
MyTest.csproj
Program.cs
# Then you can just edit Program.cs to be whatever you want it to be, and to run it, type:
dotnet run
# you'd have to be in that same directory or else you'd need to give more info than just that or it won't work.
# Make sure you're in your home directory first or somewhere where you won't run into permissions problems:
cd
# This creates a project with the name "MyTest":
dotnet new console -n 'MyTest'
# but it creates it in its own directory. So change into that dir:
cd MyTest
# in here you can use the dir command to see the files it made:
dir
# which should list at least these two files:
MyTest.csproj
Program.cs
# Then you can just edit Program.cs to be whatever you want it to be, and to run it, type:
dotnet run
# you'd have to be in that same directory or else you'd need to give more info than just that or it won't work.
Hope that helps. Or.... you could always just use an online compiler like https://dotnetfiddle.net or one of many others. Just google for "online C# compiler" and a bunch will pop up. Good luck.

Did you find this page helpful?