Page 1 of 5 123 ... LastLast
Results 1 to 15 of 72
  1. #1
    CrypTology-'s Avatar
    Join Date
    Jan 2011
    Gender
    male
    Posts
    78
    Reputation
    19
    Thanks
    2
    My Mood
    Bored

    [help]C++ beginner noob # 2

    hello guys
    i just finished learning about variables and i incorporated it into my 2nd program, but i just want to know if i made any errors with the declarations or anything like that.


    // C++ program Number 2
    # include <iostream>
    using namespace std;
    int main ()
    {
    //declaring variables
    int mpgh1;
    int mpgh2;

    // Process:
    mpgh1 = 3;
    mpgh2 = 1;
    mpgh1 = mpgh1 = 3;
    result = mpgh1 - mpgh2;

    //functions to print out the results
    cout << result;
    //terminte (ends the program)
    return 0;
    }
    msn: Dynamis-Kaizer@live.com
    Steam: holyinvoker62






    ~Goals~
    ( ) 50 Posts
    ( ) 200 Posts
    ( ) 300 Posts
    ( ) 500 Posts
    ( ) 1000 posts

    ( )MSG 4 IN combat arms
    ( ) CSM 1 IN combat arms
    ( ) Learn C++
    ( ) Get a girlfriend



    https://www.mpgh.net/forum/2-general/...t-develop.html

  2. #2
    aanthonyz's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Hitler's Minivan
    Posts
    483
    Reputation
    27
    Thanks
    83
    My Mood
    Relaxed
    What is the point of this

    Code:
    mpgh1 = mpgh1 = 3;
    You dont even need that line of code, if you already declared it with an integer at the beginning.
    "The best way to predict your future is to create it."

    Contributions I made:

    DirectX E-Books
    Hacking Tools
    Hacking into a PC

    Need Help?
    Send me a PM, or send me a email at : aanthonyz10@gmail.com

    Click My Dragon:


  3. #3
    CrypTology-'s Avatar
    Join Date
    Jan 2011
    Gender
    male
    Posts
    78
    Reputation
    19
    Thanks
    2
    My Mood
    Bored
    it was an accident i realized my mistake after i posted the thread
    msn: Dynamis-Kaizer@live.com
    Steam: holyinvoker62






    ~Goals~
    ( ) 50 Posts
    ( ) 200 Posts
    ( ) 300 Posts
    ( ) 500 Posts
    ( ) 1000 posts

    ( )MSG 4 IN combat arms
    ( ) CSM 1 IN combat arms
    ( ) Learn C++
    ( ) Get a girlfriend



    https://www.mpgh.net/forum/2-general/...t-develop.html

  4. #4
    aanthonyz's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Hitler's Minivan
    Posts
    483
    Reputation
    27
    Thanks
    83
    My Mood
    Relaxed
    Oh ok, well besides that its all good.

    Bit of advice:

    If your making a small program like this dont use:

    Code:
    using namespace std;
    just actually spell it out, so you can get into the habit of doing it. Only use it when your going to use cout or cin alot.
    "The best way to predict your future is to create it."

    Contributions I made:

    DirectX E-Books
    Hacking Tools
    Hacking into a PC

    Need Help?
    Send me a PM, or send me a email at : aanthonyz10@gmail.com

    Click My Dragon:


  5. The Following User Says Thank You to aanthonyz For This Useful Post:

    CrypTology- (02-04-2011)

  6. #5
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    I use namespace std all the time even for one liners, because I'm a lazy bastard and I know how it works anyway.

    EDIT: plus it get really old when you start using flags and end up with something like this: std::ios::in ... eww.
    Last edited by why06; 02-04-2011 at 06:29 PM.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  7. The Following 2 Users Say Thank You to why06 For This Useful Post:

    CrypTology- (02-04-2011),Hell_Demon (02-05-2011)

  8. #6
    Mookamoka's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    1
    Perfecto. Cept the extra mpgh1=

  9. #7
    whit's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    7,159
    Reputation
    490
    Thanks
    2,253
    result is undefined

  10. The Following 2 Users Say Thank You to whit For This Useful Post:

    CrypTology- (02-05-2011),Hell_Demon (02-05-2011)

  11. #8
    CrypTology-'s Avatar
    Join Date
    Jan 2011
    Gender
    male
    Posts
    78
    Reputation
    19
    Thanks
    2
    My Mood
    Bored
    thanks whit
    msn: Dynamis-Kaizer@live.com
    Steam: holyinvoker62






    ~Goals~
    ( ) 50 Posts
    ( ) 200 Posts
    ( ) 300 Posts
    ( ) 500 Posts
    ( ) 1000 posts

    ( )MSG 4 IN combat arms
    ( ) CSM 1 IN combat arms
    ( ) Learn C++
    ( ) Get a girlfriend



    https://www.mpgh.net/forum/2-general/...t-develop.html

  12. #9
    aanthonyz's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Hitler's Minivan
    Posts
    483
    Reputation
    27
    Thanks
    83
    My Mood
    Relaxed
    Quote Originally Posted by whit View Post
    result is undefined
    What do you mean result is undefined. Isnt it closing correctly because its returning 0?
    "The best way to predict your future is to create it."

    Contributions I made:

    DirectX E-Books
    Hacking Tools
    Hacking into a PC

    Need Help?
    Send me a PM, or send me a email at : aanthonyz10@gmail.com

    Click My Dragon:


  13. #10
    mookamoka3's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    110
    Reputation
    14
    Thanks
    13
    Quote Originally Posted by aanthonyz View Post
    What do you mean result is undefined. Isnt it closing correctly because its returning 0?
    He didn't declare result :P he basically just assigned a value to some random letters :3

  14. #11
    kamilos93's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    2
    My Mood
    Cool
    Quote Originally Posted by mookamoka3 View Post
    He didn't declare result :P he basically just assigned a value to some random letters :3
    Put simply, he must declare 'result' with type like int, float, unsigned int etc.. Of course there's no need now to use float or uint.

  15. #12
    mookamoka3's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    110
    Reputation
    14
    Thanks
    13
    Quote Originally Posted by kamilos93 View Post
    Put simply, he must declare 'result' with type like int, float, unsigned int etc.. Of course there's no need now to use float or uint.
    What he said

    but yeah, just int result; written pretty much anywhere before you tried to assign it a value would've been just dandy.

  16. #13
    kamilos93's Avatar
    Join Date
    Feb 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    2
    My Mood
    Cool
    Quote Originally Posted by mookamoka3 View Post
    What he said

    but yeah, just int result; written pretty much anywhere before you tried to assign it a value would've been just dandy.
    Of course he can make like You've said:
    Code:
    int result;
    result = mpgh1 - mpgh2;
    or:
    Code:
    int result = mpgh1 - mpgh2;

  17. #14
    aanthonyz's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Hitler's Minivan
    Posts
    483
    Reputation
    27
    Thanks
    83
    My Mood
    Relaxed
    Oh, I completely missed that wow...
    "The best way to predict your future is to create it."

    Contributions I made:

    DirectX E-Books
    Hacking Tools
    Hacking into a PC

    Need Help?
    Send me a PM, or send me a email at : aanthonyz10@gmail.com

    Click My Dragon:


  18. #15
    mookamoka3's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    110
    Reputation
    14
    Thanks
    13
    Quote Originally Posted by aanthonyz View Post
    Oh, I completely missed that wow...
    Same. It took me legit 10 minutes after i saw whit say it.

    Sneaky ass little error.

Page 1 of 5 123 ... LastLast