New Project

This is a discussion on New Project within the C++ Programming forums, part of the General Programming Boards category; Hey looks like imma start being a regular in this forum ok to the point I wanna start a new ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    22

    New Project

    Hey looks like imma start being a regular in this forum ok to the point I wanna start a new project and its a very simple gambling system. Its where u enter the amount of cash you want to bet and you have a 50% chance to win or lose that amount of money. I read up on file I/O but can someone explain to me how I would write code for a bank account that would save the amount of money the person has as he/she is playin?

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    You're free to invent your own file format. Perhaps follow the .ini type of thing.
    [Player1]
    name="Bob"
    money=1234.56

    [Player2]
    name="Doug"
    money=2345.67
    Once you decide on the format you want, the code to write/read the information to/from a file begins to fall into place.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    Are we talking about a couple of variables?

    Code:
    declare integer current_money;
    declare integer bet_amount;
    
    /* code that gets current money from file and assigns to current_money */
    
    while (bet_amount > current_money) {
        input bet_amount;
    }  // player must specify a bet lower than his current money
    
    /* code that does the gambling system goes here */
    
    if (won) {
        current_money += bet_amount
    } else {
        current_money -= bet_amount
    }
    
    // exiting:
    
    /* code that saves current money to file */
    
    // end:
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Some more on INI files: http://en.wikipedia.org/wiki/INI_file
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    If you're doing this under Windows you can use the GetPrivateProfileInt() (and others) API calls.

    Do a search for them: http://msdn.microsoft.com
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    22
    thx guys this makes sense to me.
    lemme try n write somethin n c if it works then run it by you guys

  7. #7
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    You'd write it in C++
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #8
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Just thought id add...

    If you are creating a project and using DevC++, remeber to click project and not source file when you start. A few people have made this error and came back complaining that they were getting linker errors. Of course, this may not apply to you so just ignore me, Im being to practical as usual...
    I'm just trying to be a better person - My Name Is Earl

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    22
    How would I set a constant to declare my starting bank account?
    I thought about just usign cout<< but that would be stupid since its only giving output

  10. #10
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    What type do you want it?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  11. #11
    Registered User
    Join Date
    Nov 2006
    Posts
    22
    o yeah i use dev c++ thanks for reminding me lol

  12. #12
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Code:
     const double bankBalance = 40.00;
    Don't forget to initalize any constant variable with a value
    I'm just trying to be a better person - My Name Is Earl

  13. #13
    Registered User
    Join Date
    Nov 2006
    Posts
    22
    this project is confusing I think I should just write source code first. which type do I choose windos app or empty? remember im new to C++ n programming

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Console Application, unless you're writing a C++ GUI application, which is highly unlikely.

    You don't need a project as long as you only have one source file and you don't need to link with anything special. Just create a new source file, save it, and compile.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #15
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Probably console app if you're new to programming.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 08:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21