My very first C++ program

Discussion in 'Programming General' started by evil-oreo, Mar 22, 2007.

My very first C++ program
  1. Unread #1 - Mar 22, 2007 at 4:58 AM
  2. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    Look below, somehow double posted sorry.

    Ill use this space to tell a little about my programming knowledge. lol

    Well 14 and a half hours from this second of writing this, I knew abosulutly NOTHING!
    Whats this and whats that, why is that and why is this? These questions came up alot.
    Thanks to the wonderful eBook of "Beginning C++ Game Programming", Im learning C++ with ease, or so it seems.
    Any program I make is written by the author of the book, I just look and re type it from character to character.
     
  3. Unread #2 - Mar 22, 2007 at 4:59 AM
  4. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    Well I just started learning c++ 4 hours ago, and following along with a really good book. Just finished chapter 1 and did the tutorial but I looked and typed the code myself so I thought it would be nice to share my first program with you guys.

    Let me know what you guys think please. And I guess I did copy paste the last 2 lines because it would close once I ran the script.
     
  5. Unread #3 - Mar 22, 2007 at 7:50 AM
  6. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    Here is my second one! Decided better to post them here then to make multiple threads.

     
  7. Unread #4 - Mar 22, 2007 at 9:18 AM
  8. SidStudios
    Joined:
    Mar 14, 2007
    Posts:
    201
    Referrals:
    0
    Sythe Gold:
    0

    SidStudios Active Member

    My very first C++ program

    Holy shit... I've done C++ from tutorials on the web and never knew that the "cin" command was that easy to use.

    Thanks for sharing your program :)
     
  9. Unread #5 - Mar 22, 2007 at 9:28 AM
  10. The End
    Joined:
    Dec 10, 2005
    Posts:
    397
    Referrals:
    0
    Sythe Gold:
    0

    The End Forum Addict

    My very first C++ program

    ohhh nice welcome to the wonderful world of programming ^>^

    and for future reference you can use [ code ] (no spaces) specifically for posting programming code
     
  11. Unread #6 - Mar 22, 2007 at 2:48 PM
  12. Tim 007
    Joined:
    Mar 11, 2007
    Posts:
    185
    Referrals:
    0
    Sythe Gold:
    0

    Tim 007 Active Member

    My very first C++ program

    Getting errors. Maybe im just too stupid.
     
  13. Unread #7 - Mar 22, 2007 at 3:23 PM
  14. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    Errors with which one?
     
  15. Unread #8 - Mar 22, 2007 at 6:02 PM
  16. The End
    Joined:
    Dec 10, 2005
    Posts:
    397
    Referrals:
    0
    Sythe Gold:
    0

    The End Forum Addict

    My very first C++ program

    Code:
    // Lost Fortune
    // A personalized adventure
    
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
    const int GOLD_PIECES = 900;
    int adventurers, killed, survivors;
    string leader;
    
    //get the information
    cout << "Welcome to Lost Fortune!\n\n";
    cout << "Please enter the following for your personalized adventure.\n";
    
    cout << "Enter a number: ";
    cin >> adventurers;
    
    cout << "Enter a number that is smaller then the first: ";
    cin >> killed;
    
    survivors = adventurers - killed;
    
    cout << "Enter a character name: ";
    cin >> leader;
    
    // Tell the story
    cout << "\nA brave group of " << adventurers << " set out on a quest ";
    cout << "-- in search of the lost treasure of the ancient dwarves.";
    cout << "The group was led by the legendary rouge, " << leader << ".\n";
    
    cout << "\nAlong the way, a band of maurading ogres ambushed the party. ";
    cout << "All fought bravely under the command of " << leader;
    cout << ", and the ogres were defeated, but at a cost. ";
    
    cout << "Of the adventurers, " << killed << " were vanquished, ";
    cout << "leaving just " << survivors << " in the group.\n";
    
    cout << "\nThe party was about to give up all hope. ";
    cout << "But while laying the deceased to rest, ";
    cout << "they stumbled upon the buried fortune. ";
    if ( GOLD_PIECES < survivors ) 
    {
         cout << "Unfortunately there wasnt enough gold to go around so " << leader << " gave all the gold to charity." << endl; 
    }
    if ( GOLD_PIECES >= survivors )
    {
    cout << "So the adventurers split " << GOLD_PIECES << " gold pieces.";
    cout << leader << " held on to the extra " << (GOLD_PIECES / survivors);
    cout << " pieces to keep things fair of course.\n";
    }
    
    system("Pause");
    return 0;
    }
    
    
    some modifications for you :D

    Code:
    // Guess My Number
    // The classic number guessing game
    
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    {
    srand (time(0));
    int theNumber = rand() % 100 + 1;
    int tries = 0, guess;
    
    cout << "\tWelcome to Guess My Number!\n\n";
    
    do
    {
    cout << "Enter a guess: ";
    cin >> guess;
    ++tries;
    
    if (guess > theNumber)
    cout << " To high!!\n\n";
    
    if (guess < theNumber)
    cout << "To low!! \n\n";
    }
    while (guess != theNumber);
    
    cout << "\nThats it! You got it in " << tries << " guesses!\n";
    
    system("pause");
    return 0;
    }
    
    originally with your homemade program halter to view the information the program would just close automatically so i put in
    Code:
    system("pause");
    
    that tells the program to halt and show information to the user and then have them press a key then it proceeds to execute the next line
     
  17. Unread #9 - Mar 22, 2007 at 6:14 PM
  18. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    //so after
    system("Pause");
    //put something like
    cout << "Press a key to continue.\n";
     
  19. Unread #10 - Mar 22, 2007 at 7:01 PM
  20. The End
    Joined:
    Dec 10, 2005
    Posts:
    397
    Referrals:
    0
    Sythe Gold:
    0

    The End Forum Addict

    My very first C++ program

    nope system("pause"); handles all that
     
  21. Unread #11 - Mar 22, 2007 at 7:41 PM
  22. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    Cool, thank you for the tip. Its gonna help lol.
     
  23. Unread #12 - Mar 22, 2007 at 9:38 PM
  24. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    Well, the end of chapter 3 in this book and this is what I have worked on.

     
  25. Unread #13 - Mar 23, 2007 at 10:30 AM
  26. SidStudios
    Joined:
    Mar 14, 2007
    Posts:
    201
    Referrals:
    0
    Sythe Gold:
    0

    SidStudios Active Member

    My very first C++ program

    Now all you need to do is work on a GUI for this gaming engine ;)
     
  27. Unread #14 - Mar 24, 2007 at 7:34 AM
  28. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    Not to that part. lol
     
  29. Unread #15 - Mar 24, 2007 at 12:51 PM
  30. SidStudios
    Joined:
    Mar 14, 2007
    Posts:
    201
    Referrals:
    0
    Sythe Gold:
    0

    SidStudios Active Member

    My very first C++ program

    Does your book teach you how to GUI program in C++?
     
  31. Unread #16 - Mar 24, 2007 at 1:12 PM
  32. SidStudios
    Joined:
    Mar 14, 2007
    Posts:
    201
    Referrals:
    0
    Sythe Gold:
    0

    SidStudios Active Member

    My very first C++ program


    I actually have no clue what a pointer and a template (in your words) is.
     
  33. Unread #17 - Mar 24, 2007 at 3:06 PM
  34. Th4 Ub3r Qu3st3r wh0 0wnz
    Joined:
    Feb 17, 2007
    Posts:
    449
    Referrals:
    0
    Sythe Gold:
    0

    Th4 Ub3r Qu3st3r wh0 0wnz Forum Addict
    Do Not Trade

    My very first C++ program

    for what you use these 3 scripts?

    btw they are nice good work;)
     
  35. Unread #18 - Mar 24, 2007 at 8:16 PM
  36. evil-oreo
    Joined:
    Dec 3, 2005
    Posts:
    40
    Referrals:
    0
    Sythe Gold:
    0

    evil-oreo Member

    My very first C++ program

    They are just scripts to practice on.
     
< FIRST RObotix | Need Help With Program Icons >

Users viewing this thread
1 guest


 
 
Adblock breaks this site