![]() |
| |||||||
| Digital Community Come here for all things digital and technological! Inside, you'll find things like hardware talk, software help, coding issues, and layout tips, among other things. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
![]() | ![]() |
| | Level: 22 | HP: 231 / 545 |
| EXP: 82% |
| ![]() | #1 (permalink) | ||
| † The Fallen Angel † |
I got on a computer programming course, and it seems to be ok so far. However, I'm having a little trouble learning the language C#. I was wondering if there was anyone on here who has worked with/knows this computer language, and if they wouldn't mind helping me out a little bit. Maybe if you have any tips, could you post them here? It would be a great help! ![]()
__________________ "I think I want to be forgiven... More than anything." ![]() "Are sins ever forgiven?" My GREAT TFF Family, and some good quotes!: | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 65 | HP: 1171 / 1622 |
| EXP: 91% |
| ![]() | #2 (permalink) | ||
| Magically Delicous | I haven't touched it in a while, but I can help out if you need it. I'm quite proficient in C-based languages so ask away. As for tips, it would depend on your experience level with programming in general and what the level of the class is. I don't want to start preaching about the proper use of curly-braces and semi-colons if you are way beyond that... haha. Also, what kind of topics are actually being covered? Is it all command-line or GUI stuff as well? Or is it C# in ASP.NET? C# is used for multiple things in .NET and they are totally different topics. ^_^ Anyways, just let me know some more info or specifics on what you need help with. | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 38 | HP: 649 / 930 |
| EXP: 20% |
| ![]() | #3 (permalink) | ||
| TFF Anarchist | Code: /* Jesus loves drunks like I like C#. Even if I do suck with it a good deal. */
using System;
namespace drunk
{
class drunk
{
static void Main()
{
System.Console.WriteLine("Drunker than a camel with humps full of rum.");
// Keep the console window open in debug mode.
System.Console.WriteLine("Press any key to sober up.");
System.Console.ReadKey();
}
}
} ![]()
__________________ ![]() My Current Game Collection I love Ann, my awesome TFF wife and real life girlfriend. Did I mention she's mindblowingly awesome? | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 7 | HP: 2 / 167 |
| EXP: 71% |
| ![]() | #4 (permalink) | ||
| Join Date: Feb 2006 Location: Malta, Europe
Posts
77 | I will start learning C from next week or the one after as part of my engineering course. It seems like it resembles Java. Can someone please explain the static void main? I've used it a couple of times but I don't know what it means.
__________________ Webmaster of Final Fantasy Tears Home | Forums | Topsites ![]() “The corpse’s crimson bitter tears flow and mingle through the endless sand feeding the chaos in me and making me stronger” Gaara | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 22 | HP: 231 / 545 |
| EXP: 82% |
| ![]() | #5 (permalink) | ||
| † The Fallen Angel † | LOL Silver! Will that one work if I start to debug? ![]() Quote:
The task we've been given was to make a program which converts cm into inches (1cm = 2.57inches). The thing is, I'm not sure about the symbols I should be using for this (* / - ...). Now, as I need to work this out on my own, I don't want an answer - just a little guidence to push me on the right path. Mainly because so far all I have is: Code: //process
lenin = lencm; ![]() EDIT: Ok... Is this ANYWHERE near rightish? Code: //process
1 = 2.57 / 2.57; ![]() EDIT: Silver, that had more build errors than my first program lol!
__________________ "I think I want to be forgiven... More than anything." ![]() "Are sins ever forgiven?" My GREAT TFF Family, and some good quotes!: Last edited by Unknown Entity; 10-02-2008 at 01:19 PM. | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 38 | HP: 649 / 930 |
| EXP: 20% |
| ![]() | #6 (permalink) | ||
| TFF Anarchist | Quote:
Considering I wrote it in a couple minutes as a joke I'd be surprised if it did really work. ![]() I thought it was a beautiful artistic expression. ![]()
__________________ ![]() My Current Game Collection I love Ann, my awesome TFF wife and real life girlfriend. Did I mention she's mindblowingly awesome? | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 65 | HP: 1171 / 1622 |
| EXP: 91% |
| ![]() | #7 (permalink) | ||
| Magically Delicous | Quote:
void simply means that the method returns nothing. You can have an int method that would return an int, for instance. Void methods do not return anything at all. So, what does this all mean? The main method is static for multiple reasons. The easy explaination is because it's the method called at the start of the program before any others that you create. I could go into a lengthy discussion explaining the difference between static and instance members, but that is probably beyond the scope of where you are at this moment. Basically, if you make a method static, it's the same every time you call it. For a variable, if it is static, it is the same no matter how many copies of that class you make. If you change that variable in one of the instances, it changes in all of them. Quote:
Here's a simple method that would do it: Code: public static double CentimetersToInches(string input)
{
// Convert argument to double for calculations.
double c = System.Double.Parse(input);
// Convert Centimeters to Inches
double i = (c * 2.57);
return i;
} Outside of your main method (inside the main class): Code: static final double CENTIMETERSTOINCHES = 2.57; Code: double i = input * CENTIMETERSTOINCHES; I think your main hangup is you don't seem to know how to use variables yet. All your calculations are typically done with variables. Well you could technically do the whole program with none, but that'd be a mess and nobody would want to debug it: Code: System.Console.Writeln("Input the number of centimeters:");
System.Console.Writeln("Centemeters to inches is {0}", (System.Double.Parse(System.Console.ReadLine())* 2.57); Double is your standard floating-point number variable. If you need to store a number with decimals, use double. Int is used for your typical non-floating-point numbers... ie: it does not store decimals. Keep that in mind... because it WILL screw up your calculations if you don't. Code: System.Console.Writeln("5 / 2.2 is: " + ((int)5 / (int)2.2));
//5 / 2 is: 2 | ||||||||
| | | ||||||||
![]() | ![]() |
| Sponsored Links |
![]() | ![]() |
| | Level: 12 | HP: 20 / 291 |
| EXP: 65% |
| ![]() | #8 (permalink) | ||
| Join Date: Jun 2007 Location: U.S.A.
Posts
185 | Oh god. I did visual basic in high school, and it was A LOT of fun, but it was quite difficult. I poked around with C++ and Java, but it was waaaay over my head. I wish the best of luck to you.
__________________ ![]() 98% of teens have tried smoking pot and drinking. If you're one of the 2% who hasn't, copy this and put it in your signature. | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 65 | HP: 1171 / 1622 |
| EXP: 91% |
| ![]() | #9 (permalink) | ||
| Magically Delicous | VB is the simplest language you can learn, besides BASIC. It really should only be taught to non-majors, IMHO. I always get a good laugh when people start bragging that they are certified in Visual BASIC or swear by that language. They honestly think it's a hardcore programming language and that they are doing something elite. Um... no. It has the word "basic" in it for a reason. But enough of my soap box, if you need programming help I can do that. I won't post the entire code for completing something, but I will give you the necessary tools to help you learn and figure problems out. Most of the time you spend programming is debugging. You've got to learn from the start how to do it or else you'll never succeed. | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 22 | HP: 231 / 545 |
| EXP: 82% |
| ![]() | #10 (permalink) | ||
| † The Fallen Angel † | Thanks for all your help Tech Support! I shoulda replied earlier, but I was scared that I'd never work it out... ![]() But I worked out how to do it! O_O I wrote a program on how to divide any number by 12! Code: int stnumber;
int ndnumber;
//input
Console.WriteLine("Enter number to be divided >");
stnumber = int.Parse(Console.ReadLine());
//process
ndnumber = stnumber / 12;
//output
Console.WriteLine("Answer is {0}:", ndnumber);
Console.ReadLine();
__________________ "I think I want to be forgiven... More than anything." ![]() "Are sins ever forgiven?" My GREAT TFF Family, and some good quotes!: Last edited by Unknown Entity; 10-09-2008 at 01:59 PM. | ||||||||
| | | ||||||||
![]() | ![]() |
![]() | ![]() |
| | Level: 65 | HP: 1171 / 1622 |
| EXP: 91% |
| ![]() | #11 (permalink) | ||
| Magically Delicous | >_> 5/12 = 0.4166666666666_ But your prog will give : 5/12 = 0. ![]() If you're only allowed to use integers that is fine, but you'll always have truncation(the decimals are chopped off), which means your results will only be accurate if the entered number is evenly divisible by 12. Try lots of numbers and see. Always use double if your result has the possibility of having decimals. ![]() In other news, while you can name variables whatever the heck you want, it's always a good idea for clarity sake to name them something easily understandable/readable by anyone like numerator, total, inNum, outNum, etc. It's just a recommendation, but teachers will love you and when you have to check your code for errors, it makes it so much easier. Trust me, when you get to a lot of lines of code, you won't remember what the heck ndnumber was for. ^_^ edit: Oh do remember my point from my previous post... if you make 'ndnumber' into a double, it will still be wrong. An integer divided by an integer placed in a double is still an integer...then it adds .0 after it. ie: ndnumber = 0.0 You can easily get around that though. just add a .0 to 12. Code: int stnumber;
double ndnumber;
//input
Console.WriteLine("Enter number to be divided >");
stnumber = int.Parse(Console.ReadLine());
//process
ndnumber = stnumber / 12.0;
//output
Console.WriteLine("Answer is {0}:", ndnumber);
Console.ReadLine(); ![]() | ||||||||
| | | ||||||||
![]() | ![]() |