• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=Vbits;25481178]If i wanted to write a irc server then where would i look to get a tutorial or documentation.[/QUOTE] [url]http://tools.ietf.org/html/rfc2812[/url]
[QUOTE=Vbits;25481178]If i wanted to write a irc server then where would i look to get a tutorial or documentation.[/QUOTE] [url]http://blog.webicity.info/2010/10/14/a-quick-basic-primer-on-the-irc-protocol/[/url]
Can anyone help me with my problem described in the "what are you working on" thread? [url]http://www.facepunch.com/showthread.php?1000894-What-Are-You-Working-On-V13&p=25489311&viewfull=1#post25489311[/url]
[QUOTE=CommanderPT;25489424]Can anyone help me with my problem described in the "what are you working on" thread? [url]http://www.facepunch.com/showthread.php?1000894-What-Are-You-Working-On-V13&p=25489311&viewfull=1#post25489311[/url][/QUOTE] [cpp]import javax.swing.JOptionPane; public class leapyear { public static void main(String[] arg) { String s = JOptionPane.showInputDialog(null, "Type in a year.", "2012"); int i = Integer.parseInt(s); if (Calendar.isLeapYear(i)) { JOptionPane.showMessageDialog(null, i + " is a leapyear."); } else { JOptionPane.showMessageDialog(null, i + " is not a leapyear."); } } static class Calendar { public static boolean isLeapYear(int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return 1; else return 2; } } }[/cpp] For the if-else problem, you had the syntax wrong. It should be [cpp]if (bool) { //stuff } else { //other stuff }[/cpp] There's no semicolor after the condition of if (You had "if (bool)[b];[/b]") Instead of returning an int and checking the modulo, you should just use booleans.
Thank you. It works now. [editline]18th October 2010[/editline] Actually, it doesn't. It doesn't see 2012 as a leap year, which is incorrect but not 2016 which also is one. Hmm.
1 and 2 evaluate to true, since they're != 0. You should return true and false respectively from the isLeapYear-function.
Woo, I fixed it! [cpp] if (v % 2 != 1) JOptionPane.showMessageDialog(null, i + " is a leap year."); else JOptionPane.showMessageDialog(null, i + " is not a leap year."); } [/cpp] I first had that. Changed it to == 1 from != 1. Now it works fine. [editline]18th October 2010[/editline] [QUOTE=ZeekyHBomb;25490509]1 and 2 evaluate to true, since they're != 0. You should return true and false respectively from the isLeapYear-function.[/QUOTE] Heh, I just noticed as you posted. Thanks though. [editline]18th October 2010[/editline] [QUOTE=ZeekyHBomb;25490509]1 and 2 evaluate to true, since they're != 0. You should return true and false respectively from the isLeapYear-function.[/QUOTE] I am actually supposed to return true and false but I couldn't figure it out so I just went with that. I'll ask my teacher about it tomorrow.
Why do you even still have that? It should be 'if (Calendar.isLeapYear(i)) {' like it was posted by raBBish.
[QUOTE=ZeekyHBomb;25490509]1 and 2 evaluate to true, since they're != 0. You should return true and false respectively from the isLeapYear-function.[/QUOTE] I am actually supposed to return true and false but I couldn't figure it out so I just went with that. I'll ask my teacher about it tomorrow.
You have an unmatched brace on the last line. If that's not closing one you started before that code snippet, you'll get an error.
[QUOTE=ZeekyHBomb;25490594]Why do you even still have that? It should be 'if (Calendar.isLeapYear(i)) {' like it was posted by raBBish.[/QUOTE] Figured I shouldn't just copy paste his without understanding it first. :v: And I also get an error when I paste it in. Saying I can't convert boolean to int or something. [QUOTE=Darwin226;25490621]You have an unmatched brace on the last line. If that's not closing one you started before that code snippet, you'll get an error.[/QUOTE] Fixed that actually. The program does work. But I guess it's a bit clunky.
What's your current code like?
[cpp] import javax.swing.JOptionPane; public class leapyear { public static void main(String[] arg) { String s = JOptionPane.showInputDialog(null, "Type in a year.", "2012"); int i = Integer.parseInt(s); int v = Calendar.leap(i); if (v % 2 == 1) JOptionPane.showMessageDialog(null, i + " is a leap year."); else JOptionPane.showMessageDialog(null, i + " is not a leap year."); } } class Calendar { public static int leap (int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return (1); else return (2); } } [/cpp] [editline]18th October 2010[/editline] Like that.
[QUOTE=CommanderPT;25490930][cpp] import javax.swing.JOptionPane; public class leapyear { public static void main(String[] arg) { String s = JOptionPane.showInputDialog(null, "Type in a year.", "2012"); int i = Integer.parseInt(s); int v = Calendar.leap(i); if (v % 2 == 1) JOptionPane.showMessageDialog(null, i + " is a leap year."); else JOptionPane.showMessageDialog(null, i + " is not a leap year."); } } class Calendar { public static int leap (int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return (1); else return (2); } } [/cpp] [editline]18th October 2010[/editline] Like that.[/QUOTE] [cpp] import javax.swing.JOptionPane; public class leapyear { public static void main(String[] arg) { String s = JOptionPane.showInputDialog(null, "Type in a year.", "2012"); int i = Integer.parseInt(s); if (Calendar.leap(i)) JOptionPane.showMessageDialog(null, i + " is a leap year."); else JOptionPane.showMessageDialog(null, i + " is not a leap year."); } } class Calendar { public static boolean leap (int year) { return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0); } }[/cpp]
[QUOTE=thomasfn;25491168][cpp] import javax.swing.JOptionPane; public class leapyear { public static void main(String[] arg) { String s = JOptionPane.showInputDialog(null, "Type in a year.", "2012"); int i = Integer.parseInt(s); if (Calendar.leap(i)) JOptionPane.showMessageDialog(null, i + " is a leap year."); else JOptionPane.showMessageDialog(null, i + " is not a leap year."); } } class Calendar { public static bool leap (int year) { return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0); } }[/cpp][/QUOTE] It's boolean in Java, not bool.
[QUOTE=ZeekyHBomb;25491288]It's boolean in Java, not bool.[/QUOTE] Oh it's java, thought it was c# for some reason (even though it imports javax.stuff).
[QUOTE=CommanderPT;25490930][cpp] import javax.swing.JOptionPane; public class leapyear { public static void main(String[] arg) { String s = JOptionPane.showInputDialog(null, "Type in a year.", "2012"); int i = Integer.parseInt(s); int v = Calendar.leap(i); if (v % 2 == 1) JOptionPane.showMessageDialog(null, i + " is a leap year."); else JOptionPane.showMessageDialog(null, i + " is not a leap year."); } } class Calendar { public static int leap (int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return (1); else return (2); } } [/cpp] [editline]18th October 2010[/editline] Like that.[/QUOTE] Just so you don't learn the wrong syntax I'll point out that the closing brace that has the same indentation as the else in the main function is not actually closing the if, it's closing the function.
So I've just finished reading through an entire book teaching c++... I'd like to go on with the basics I've learnt to something a little more useful. Such as a simple simple game... Should I look up DirectX tutorials? Or what do people recommend?
[QUOTE=thomasfn;25491168][cpp] import javax.swing.JOptionPane; public class leapyear { public static void main(String[] arg) { String s = JOptionPane.showInputDialog(null, "Type in a year.", "2012"); int i = Integer.parseInt(s); if (Calendar.leap(i)) JOptionPane.showMessageDialog(null, i + " is a leap year."); else JOptionPane.showMessageDialog(null, i + " is not a leap year."); } } class Calendar { public static boolean leap (int year) { return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0); } }[/cpp][/QUOTE] The thing I don't get is. How does the program know to check if the value % 2 == 1? You never tell it to check so how does it know that? You just call the Calendar. Doesn't that mean it will just display whatever value it gets? [editline]18th October 2010[/editline] Oh wait I think I got it now. [editline]18th October 2010[/editline] So by doing that instead of the way I did it. It will send the value of true instead of 1. So I don't have to check weather it is 1 or 2. Since it will only return a value if it is true. Then it just checks if it is true or false in the main class automatically, right?
When you write year % 4 == 0 it evaluates to true or false, same for 100 and 400. Then it checks if both first and the second one are true, if yes, then it evaluates to true, if not it evaluates to false. Then it checks if it evaluated to true OR year % 400 is true and returns that. That sounded way more complicated than it actually is, sorry. Basically year % 4 will give you a number (0, 1, 2, 3) but you have == 0 next to it which will give you a true it year % 4 is 0 obviously, otherwise it will give you false.
So the if (Calendar.leap(i)) basically checks if (true)? [editline]18th October 2010[/editline] And thanks for all the help! :buddy: [editline]18th October 2010[/editline] And thanks for all the help! :buddy:
[QUOTE=CommanderPT;25492757]So the if (Calendar.leap(i)) basically checks if (true)?[/QUOTE] That's all that if does actually. It checks if the condition is true or false. In this case, the function leap() returns that true/false value.
[QUOTE=Darwin226;25492830]That's all that if does actually. It checks if the condition is true or false. In this case, the function leap() returns that true/false value.[/QUOTE] At last I got it. Thank you yet again and to everyone else who helped.
[QUOTE=CommanderPT;25492757]So the if (Calendar.leap(i)) basically checks if (true)? [editline]18th October 2010[/editline] And thanks for all the help! :buddy: [editline]18th October 2010[/editline] And thanks for all the help! :buddy:[/QUOTE] "if (Calendar.leap(i))" is, in this case, the same as "if (Calendar.leap(i) == true)".
[QUOTE=Capsup;25492235]So I've just finished reading through an entire book teaching c++... I'd like to go on with the basics I've learnt to something a little more useful. Such as a simple simple game... Should I look up DirectX tutorials? Or what do people recommend?[/QUOTE] SDL or SFML. Apparently SFML is being used more nowadays.
Also note that ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) could be written as: [cpp]if ( year % 4 == 0 ) { if ( year % 100 != 0 ) { return true; } } if ( year % 400 == 0 ) return true;[/cpp]
How do I prevent a Sprite from scaling when I resize the rectangle it is drawn onto? I'm using XNA.
[QUOTE=esalaka;25492971]SDL or SFML. Apparently SFML is being used more nowadays.[/QUOTE] SFML seems interesting. Thanks for that.
Could someone tell me why LOVE is saying I need another end statement. It seems correct. (My LUA is a little rusty) [URL Snipped, see below]
[QUOTE=Phyxius;25496655]Could someone tell me why LOVE is saying I need another end statement. It seems correct. (My LUA is a little rusty) [url]http://pastebin.com/ExRHRg5y[/url][/QUOTE] You'll want to paste the entire file, and the exact error message. (Also, Lua is not an acronym)
Sorry, you need to Log In to post a reply to this thread.