New OOTS products from CafePress
New OOTS t-shirts, ornaments, mugs, bags, and more
Page 8 of 12 FirstFirst 123456789101112 LastLast
Results 211 to 240 of 356

Thread: ProgrammersitP

  1. - Top - End - #211
    Ogre in the Playground
    Join Date
    Nov 2006

    Default Re: ProgrammersitP

    Quote Originally Posted by Inglenook View Post
    I've started learning Python fairly recently with the end goal of creating a (relatively) simple computer game.

    I've got most of the basics done, so far—character selection, saving and loading games, etc. But the lack of a GUI is driving me crazy on some fundamental level. And I have a niggling worry that I'll finish the game only to discover that I have to start from scratch because I didn't design my code around the GUI. So I'd like to work on the game logic + GUI simultaneously.
    You might want to initially consider the GUI as an interface between users and the command line interface. So rather than scripting a button to perform some action, script the button to call the command line script with some parameters to perform said action. Then when you go to build your GUI, you can go back and change things.

    Another way of looking at this is the Model-View-Controller.

    My problem is trying to find the right combo of language and GUI framework. And I guess the former should take precedence over the latter, so these are the main four I've been looking at:

    • Python: I have a working knowledge of it already, but there seems to be a surprising lack of coherent documentation. I understand that programming is jargon-y by nature, but it feels almost as if the people who write the documentation go out of their way to be exclusive of beginners. Plus there's the whole 2.7/3.x divide that makes the right documentation even harder to find. And a lot of the GUI frameworks for Python seem to be dead projects (e.g. Pygame?).
    • C++: I've heard this is a really good language to know all-around, but I've also heard that it's much more confusing than Python, and much harder to read. And I don't really understand its strengths and weaknesses compared to, say, Python. But it seems to be infinitely better documented.
    • C#: Windows-only, I think? So I'd rather use something else.
    • Java: I'm trying to avoid Java, since I've been told that it's going the way of the dinosaur (perhaps even more quickly due to the recent security problems).

    I don't think there's an engine for the type of game I'm writing (sort of stat-based strategy, strongly text-based), so I'm looking for a framework for now.

    Ideally I'd like something cross-platform. I don't need anything complicated as far as GUI—text, buttons, forms, photos, and that's it. But I have no idea what sort of technical features I'm supposed to be looking for in a framework.

    TL;DR version: For programming a simple(ish) game, is it worth learning a language other than Python in order to have better documentation and GUI frameworks? And what framework should I use?

    ETA: And I've tried TKinter for Python, and it seemed pretty awful. And I've heard people say it's awful compared to a lot of frameworks.
    Python is perhaps the best documented language I have ever used. What are you looking for in a graphics framework? If you're looking to do game programming, remember that a lot of graphics frameworks (e.g. Java Swing) are focused on producing windows and event driven interfaces.

  2. - Top - End - #212
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    I'm in a programming debate with one of my friends. (About Java)

    Are public variables fine, or should you provide accessors/mutators? Defend your position.
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  3. - Top - End - #213
    Titan in the Playground
     
    PairO'Dice Lost's Avatar

    Join Date
    Dec 2008
    Location
    Malsheem, Nessus
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Razanir View Post
    I'm in a programming debate with one of my friends. (About Java)

    Are public variables fine, or should you provide accessors/mutators? Defend your position.
    Depends entirely on the scope and intended use of your project. The product my team is developing at work has several hundred thousand lines in several dozen files, and it interacts with more than four other products developed by different teams. It's not in Java, but it still has global variables accessible by outside functions, and in that context using public variables that could be modified from anywhere would be an absolute nightmare for debugging and workflow tracing.

    I've also written many programs for my own use, which are narrowly-scoped and fairly small; I've given them to plenty of people to use, but I'm the only one who's ever going to work on them. In that context, writing up accessors and mutators for all the variables I need to use in multiple files is a waste of time and effort, since I wouldn't really gain any of the benefits of encapsulation.

    Most of the time, the problems caused by public variables arise when someone thinks they're working on the latter kind of project but either it is the former kind or it was the former kind and grew into the latter kind over time. As long as you use accessors and mutators when they're really needed, using public variables the rest of the time is fine.
    Better to DM in Baator than play in Celestia
    You can just call me Dice; that's how I roll.


    Spoiler: Sig of Holding
    Show

    Quote Originally Posted by abadguy View Post
    Darn you PoDL for making me care about a bunch of NPC Commoners!
    Quote Originally Posted by Chambers View Post
    I'm pretty sure turning Waterdeep into a sheet of glass wasn't the best win condition for that fight. We lived though!
    Quote Originally Posted by MaxiDuRaritry View Post
    Quote Originally Posted by PairO'DiceLost View Post
    <Snip>
    Where are my Like, Love, and Want to Have Your Manchildren (Totally Homo) buttons for this post?
    Won a cookie for this, won everything for this

  4. - Top - End - #214
    Barbarian in the Playground
    Join Date
    Jul 2007
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Razanir View Post
    I'm in a programming debate with one of my friends. (About Java)

    Are public variables fine, or should you provide accessors/mutators? Defend your position.
    I have the philosophy that variables should be as public as possible. If the variable can hold any value, and I`m sure it would be the same with subclasses, I make it public (changing it directly couldn`t harm the code, so why write unnescery getter and setter methods?).

    If I want to preform some other actions whenever the value is changed, or if certain values would cause issues (null for Object refrence, in some cases) I make the variable protected.

    If, for some reason, I want to make sure that even subclasses would be restricted in their ability to modify the variable, I make it private.
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  5. - Top - End - #215
    Barbarian in the Playground
     
    BardGuy

    Join Date
    Feb 2010
    Location
    UK
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Razanir View Post
    I'm in a programming debate with one of my friends. (About Java)

    Are public variables fine, or should you provide accessors/mutators? Defend your position.
    A common school of thought is to keep a variable private unless it you have situation:

    Code:
    class Foo {
    private:
        Bar x;
    public:
        Bar getX() const {return x;}
        void setX(Bar val) {x = val;}
    };
    You might as well just make x public, right?

    However, I have found that I've been in this situation and I've wanted to replace x* with something else (whenever I used it it was being converted into different units which weren't human friendly) so I changed it to get() and set() functions which would do the conversion for me because this conversion was happening thousands of times per frame and became a real bottleneck.

    This made me wish I'd kept x private and just used get()/set() functions for it because I could have just changed the class definition. As it was I had to go and change the many references to it by hand. :-(

    *It wasn't actually called x. I forget what exactly it was.

  6. - Top - End - #216
    Titan in the Playground
    Join Date
    Mar 2009
    Location
    Sweden
    Gender
    Male

    Default Re: ProgrammersitP

    The official Java Code Convention discourages public class or instance variables unless there's a good reason for it. Writing basic getters and setters is no great effort to start with anyway.
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  7. - Top - End - #217
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Teddy View Post
    The official Java Code Convention discourages public class or instance variables unless there's a good reason for it. Writing basic getters and setters is no great effort to start with anyway.
    I looked it up and saw this:
    One example of appropriate public instance variables is the case where the class is essentially a data structure, with no behavior. In other words, if you would have used a struct instead of a class (if Java supported struct), then it's appropriate to make the class's instance variables public.
    What if the only methods it contains beyond getters and setters are for exporting XML and JSON? It sounds now to me like that would be an appropriate place to use public variables (which goes against everything I learned in AP)
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  8. - Top - End - #218
    Titan in the Playground
    Join Date
    Mar 2009
    Location
    Sweden
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Razanir View Post
    What if the only methods it contains beyond getters and setters are for exporting XML and JSON? It sounds now to me like that would be an appropriate place to use public variables (which goes against everything I learned in AP)
    Well, if you know for sure that you never will want to add or change functionality, and no one else other than you is going to have to maintain or interface your code, well, then I suppose it's okay. But as I said, writing getters and setters is a non-effort, and can generally be done automatically in more advanced IDEs.
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  9. - Top - End - #219
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Teddy View Post
    Well, if you know for sure that you never will want to add or change functionality, and no one else other than you is going to have to maintain or interface your code, well, then I suppose it's okay. But as I said, writing getters and setters is a non-effort, and can generally be done automatically in more advanced IDEs.
    Yeah... I'm still using BlueJ (although I am using getters and setters).

    Does anyone have a recommendation for a more advanced IDE that still has that map of all your classes and dependencies? That part of the interface is the only real reason I'm still using BlueJ; I don't want to give it up
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  10. - Top - End - #220
    Ogre in the Playground
    Join Date
    Oct 2009

    Default Re: ProgrammersitP

    Quote Originally Posted by Razanir View Post
    Yeah... I'm still using BlueJ (although I am using getters and setters).

    Does anyone have a recommendation for a more advanced IDE that still has that map of all your classes and dependencies? That part of the interface is the only real reason I'm still using BlueJ; I don't want to give it up
    I´m going to sound like a broken record but
    IntelliJ, it even has it in a pretty nice matrix structure

    http://www.jetbrains.com/idea/featur..._analysis.html

    or the normal uml class diagram

    http://www.jetbrains.com/idea/featur...s_diagram.html
    Last edited by Emmerask; 2013-01-28 at 09:09 PM.

  11. - Top - End - #221
    Barbarian in the Playground
    Join Date
    Jul 2007
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Teddy View Post
    The official Java Code Convention discourages public class or instance variables unless there's a good reason for it. Writing basic getters and setters is no great effort to start with anyway.
    I`d like to note that some classes in the offical Java API break this convention.
    Exemples:
    Last edited by akma; 2013-01-29 at 05:32 AM.
    Madly In Science, an RPG in which you play mad scientists, you can get it for free.

    Spoiler: Some other things.
    Show
    A world behind the mirror (stand alone plane)
    (Wall) passer, a rogue variant
    My not realy extanded homebrewer signature

    Quote Originally Posted by Grinner View Post
    In a world ruled by small birds, mankind cannot help but wonder how this state of affairs came about.

  12. - Top - End - #222
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by akma View Post
    I`d like to note that some classes in the offical Java API break this convention.
    Exemples:
    Oh wow, it does.

    java.awt.Polygon, lines 253-260:
    Code:
            if (x < bounds.x) {
                bounds.width = bounds.width + (bounds.x - x);
                bounds.x = x;
            }
            else {
                bounds.width = Math.max(bounds.width, x - bounds.x);
                // bounds.x = bounds.x;
            }
    I think by the conventions, wouldn't it be } else { all on one line?
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  13. - Top - End - #223
    Barbarian in the Playground
     
    Ashtar's Avatar

    Join Date
    Jun 2007
    Location
    Switzerland
    Gender
    Male

    Default Re: ProgrammersitP

    Just wondering if any of you has had (or has) access to an Intel Xeon Phi card? I would love to run a benchmark problem before I receive it in the office.

    We should be getting one in the office mid-february to run our massive optimisations of energy assets on. I am very excited! Hardware has really advanced massively in the last few years with the advent of graphic card number crunchers, sadly the problem we have was not one that translated to the graphic card easily, whereas the Xeon phi is just a 60 core, 240 thread monster that I expect will give us excellent numbers...

    So do any of you do highly parallel programming, optimization problems or large workloads? OpenMP, MPI or others parallelization techniques?

  14. - Top - End - #224
    Titan in the Playground
     
    Mystic Muse's Avatar

    Join Date
    Mar 2009

    Default Re: ProgrammersitP

    I need some help with a program for school that I'm derping on. Miscrosoft Visual Basic 2010

    Spoiler
    Show


    I'm supposed to fix the error, but I can't remember/think of how.
    Last edited by Mystic Muse; 2013-02-02 at 02:50 AM.

  15. - Top - End - #225
    Ogre in the Playground
    Join Date
    Oct 2009

    Default Re: ProgrammersitP

    You can´t make a label to a string, a label object is a lot more then the string it displays, it will most likely (not a vb expert^^) have stuff like textcolor, backgroundcolor, other format stuff, enabled disabled bool etc in it.

    what you can do however is

    lblEnding.Text = decEnding.ToString("2")

    ie setting the text of the label to the string
    Last edited by Emmerask; 2013-02-02 at 08:07 AM.

  16. - Top - End - #226
    Titan in the Playground
     
    Mystic Muse's Avatar

    Join Date
    Mar 2009

    Default Re: ProgrammersitP

    Thanks a bunch.

    I'll be sure to remember this thread when I'm having trouble with homework in the future.

  17. - Top - End - #227
    Ogre in the Playground
    Join Date
    Nov 2006

    Default Re: ProgrammersitP

    Quote Originally Posted by Ashtar View Post
    Just wondering if any of you has had (or has) access to an Intel Xeon Phi card? I would love to run a benchmark problem before I receive it in the office.

    We should be getting one in the office mid-february to run our massive optimisations of energy assets on. I am very excited! Hardware has really advanced massively in the last few years with the advent of graphic card number crunchers, sadly the problem we have was not one that translated to the graphic card easily, whereas the Xeon phi is just a 60 core, 240 thread monster that I expect will give us excellent numbers...

    So do any of you do highly parallel programming, optimization problems or large workloads? OpenMP, MPI or others parallelization techniques?
    I do a lot of OpenCL programming. Haven't had a chance to use one of the Intel cards though. We were more interested in scaling across multiple GPUs, and I'd much rather submit jobs to the supercomputer for MPI work.

    Let me know how it goes though! My mentor was looking into buying a rig of Teslas, so...

  18. - Top - End - #228
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    Is this bad practice?
    Code:
    public class SomeClass {
        private OtherClass o = new OtherClass();
    
        public void someMethod() {
            System.out.println(o.var);
        }
    
        private class OtherClass {
            private int var = 3;
        }
    }
    Last edited by Razanir; 2013-02-02 at 06:02 PM.
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  19. - Top - End - #229
    Barbarian in the Playground
     
    Ashtar's Avatar

    Join Date
    Jun 2007
    Location
    Switzerland
    Gender
    Male

    Default Re: ProgrammersitP

    Well it simply shouldn't work. The OtherClass.var being private means it cannot be accessed from the outside, not even to be read. In java, it should either be public, protected or without modifier (see here).

    Oops, sorry, forgot about the rules of Nested classes in java. Carry on, it would work. Since it's a nested class, the outer class has access to the inner private variables.

    A class instantiating another is not bad practice, but I would recommend to instantiate the OtherClass inside the SomeClass constructor (which you didn't have here in this example).
    Last edited by Ashtar; 2013-02-02 at 08:19 PM.

  20. - Top - End - #230
    Ogre in the Playground
     
    NecromancerGuy

    Join Date
    May 2009

    Default Re: ProgrammersitP

    What're some examples of when using nested classes would be good? Looking at Ashtar's link, I can't really imagine when you would use one instead of incorporating that code into the main class.

  21. - Top - End - #231
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Ashtar View Post
    A class instantiating another is not bad practice, but I would recommend to instantiate the OtherClass inside the SomeClass constructor (which you didn't have here in this example).
    Oh no, I actually am instantiating it in the constructor; I just left that out to highlight the part I need.

    @Ithilanor It's a simple data storing class so I don't need two parallel arrays
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  22. - Top - End - #232
    Titan in the Playground
    Join Date
    Mar 2009
    Location
    Sweden
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Razanir View Post
    Is this bad practice?
    Spoiler
    Show
    Code:
    public class SomeClass {
        private OtherClass o = new OtherClass();
    
        public void someMethod() {
            System.out.println(o.var);
        }
    
        private class OtherClass {
            private int var = 3;
        }
    }
    Not as far as I know. Since the nestled class is private, you don't have to be afraid that someone will use the direct access to modify the value illegitimately.

    Quote Originally Posted by IthilanorStPete View Post
    What're some examples of when using nested classes would be good? Looking at Ashtar's link, I can't really imagine when you would use one instead of incorporating that code into the main class.
    Sometimes you need a class for a task inside another class, but which holds no use outside said class (concider a list element in a specific type of list. Even if you make other lists, you may want to give them a different intern representation).

    Other times, you may have a class so strongly linked to the first class that even if you make it public, you may want to nestle it inside the first class to make the relationship obvious (consider an Exception for a specific type of behaviour of the first class. Even if you might want to raise said exception outside the first class, making the relationship obvious is a good way to prevent misuse).
    Last edited by Teddy; 2013-02-03 at 05:04 AM.
    Clouddreamer Teddy by me, high above the world, far beyond its matters...

    Spoiler: Banner by Vrythas
    Show

  23. - Top - End - #233
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    printf and NumberFormat. Both work just fine for formatting numbers for output. How would I go about it if I wanted some dollar amounts in accounting format

    Code:
    NumberFormat.getCurrencyFormat():
      $1.00
     $10.00
    $100.00
    
    Accounting format:
    $  1.00
    $ 10.00
    $100.00
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  24. - Top - End - #234
    Barbarian in the Playground
     
    BardGuy

    Join Date
    Feb 2010
    Location
    UK
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Razanir View Post
    printf and NumberFormat. Both work just fine for formatting numbers for output. How would I go about it if I wanted some dollar amounts in accounting format

    Code:
    NumberFormat.getCurrencyFormat():
      $1.00
     $10.00
    $100.00
    
    Accounting format:
    $  1.00
    $ 10.00
    $100.00
    For printf() you'd use the width and precision modifier: "%[width].[precision]f" for a float. Precision is the number of decimal places and width is the number of characters it takes up (including decimal point), so your second example would be:
    Code:
    printf("$%6.2f",val);
    I personally prefer cout:
    Code:
    cout << "$" << setiosflags(ios::fixed)
        << right << setwidth(6) << setprecision(2) << val;
    I realise this is far more verbose than printf, but also (I think) easier to read and easier to customise programmatically.
    Last edited by Capt Spanner; 2013-02-08 at 07:49 PM.

  25. - Top - End - #235
    Ogre in the Playground
    Join Date
    Oct 2011
    Location
    The last place you look
    Gender
    Male

    Default Re: ProgrammersitP

    Quote Originally Posted by Capt Spanner View Post
    For printf() you'd use the width and precision modifier: "%[width].[precision]f" for a float. Precision is the number of decimal places and width is the number of characters it takes up (including decimal point), so your second example would be:
    Code:
    printf("$%6.2f",val);
    I personally prefer cout:
    Code:
    cout << "$" << setiosflags(ios::fixed)
        << right << setwidth(6) << setprecision(2) << val;
    I realise this is far more verbose than printf, but also (I think) easier to read and easier to customise programmatically.
    It's also not supported in the language I'm using (Java)
    Avatar by Venetian Mask. It's of an NPC from a campaign I may yet run (possibly in PbP) who became a favorite of mine while planning.

    Quote Originally Posted by Razanir View Post
    Everyone knows frying pans are actually weapons that people repurpose for cooking
    I am a 10/14/11/15/12/14 LG Clr 2

  26. - Top - End - #236
    Ogre in the Playground
    Join Date
    Jul 2007
    Location
    Airstrip One

    Default Re: ProgrammersitP

    Quote Originally Posted by Razanir View Post
    It's also not supported in the language I'm using (Java)
    Fortunately, Java does implement a number of printf functions, including one in PrintStream, and helpfully they use a format syntax drawn from C. If you want to store the string internally, you can use the String.format function instead. There are other ways of doing it, but those two both work.

    Example code using your data and the format string from Capt Spanner:
    Spoiler
    Show
    Code:
    class FormatDemo {
        public static void main(String[] args) {
    	String format = "$%6.2f%n";
    	// The addition of a %n to the format string just adds a line
    	// break at the end.
    
    	// Using printf()
    	System.out.printf(format, (float) 1);
    	System.out.printf(format, (float) 10);
    	System.out.printf(format, (float) 100);
    	// The values need to be cast because otherwise an exception
    	// is thrown - Integers are not floating points but neither
    	// is the precision field valid when formatting integers.
    	System.out.println();
    
    	// Using String.format()
    	String val1 = String.format(format, (float) 1);
    	String val2 = String.format(format, (float) 10);
    	String val3 = String.format(format, (float) 100);
    	System.out.print(val1);
    	System.out.print(val2);
    	System.out.print(val3);
        }
    }
    Output:
    Code:
    $  1.00
    $ 10.00
    $100.00
    
    $  1.00
    $ 10.00
    $100.00

  27. - Top - End - #237
    Titan in the Playground
     
    Mystic Muse's Avatar

    Join Date
    Mar 2009

    Default Re: ProgrammersitP

    Okay, I need some help again. (Microsoft Visual Basic)

    Spoiler
    Show


    Here's what the base program looks like. I need to modify it so that the program can calculate a sales commission based on the number entered, using the (As the book calls it) If/ElseIf/Elf form of the Ef then else statement.


    Monthly sales
    Commission Rate
    0-19,999.99
    4%
    20,000-29,999.99
    5%
    30,000-39,999.99
    6%
    40,000-49,999.99
    7%
    50,000 or more
    9%
    Less than 0
    0%

    Spoiler
    Show


    There's what the program itself looks like, if that'll help at all.

    EDIT: I specifically have to enter in 22,000 and get back the commission accurate to 2 decimal places.
    Last edited by Mystic Muse; 2013-02-11 at 04:51 AM.

  28. - Top - End - #238
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: ProgrammersitP

    You'd have to do something like assigning the values from the text box to a numeric variables (say, MonthlySales), then do your calculation:

    If MonthlySales < 0 Then Commission = 0
    Else If MonthlySales >= 0 And MonthlySales <= 19999999 Then Commission = MonthlySales * 0.04
    .
    .
    .
    Else Commission = MonthlySales * 0.09
    End If

    (The bit in the middle left as an exercise for the reader). Have to say that I wouldn't use an If...Then construct for this anyway, because it's going to be a pain to maintain if any of the brackets or percentages change, but if that's what the book is telling you to do that's the way to go about it.

  29. - Top - End - #239
    Ogre in the Playground
    Join Date
    Oct 2009

    Default Re: ProgrammersitP

    You could also just start with the highest and work down to lowest, this way you only have to check against one statement ie:

    if MonthlySales >= 50000 Then Commission = MonthlySales * 0.09
    else if MonthlySales >= 40000 Then Commission = MonthlySales * 0.07
    .
    .
    .
    else if MonthlySales >= 0 Then Commission = MonthlySales * 0.04

    at least if vb treats else if the same as java which I´m fairly certain it will
    ie leave the rest of the else ifs alone after finding the first correct one...after all why call it ELSE if otherwise

    /edit oh and don´t forget to check the user entry in the MonthlySales Field, either check it after the user typed or make the textfield only accept numeric values and points.
    Last edited by Emmerask; 2013-02-11 at 02:12 PM.

  30. - Top - End - #240
    Ogre in the Playground
    Join Date
    Nov 2006

    Default Re: ProgrammersitP

    Does anyone here have any skill with C systems programming? I've been trying to read file permissions of all files in a directory, but everything comes up [----------] (i.e. 000) when I lstat() and bitwise & to check the flag.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •