Results 1 to 10 of 10
  1. #1
    Ronon666's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    What are you? A stalker?
    Posts
    122
    Reputation
    8
    Thanks
    46
    My Mood
    Bored
    Hey guys, i was trying to make a fun .exe file which could help my friends(they are really stupid bout math) or just be for fun (i started learning c++ today and wanted to make something cool so dont start QQ about how shtty this is)

    What the .exe does is that it multiplies the number the user inputs with the same number, (Makes it squared, lets say mm2,cm2,dm2,m2,km2 and alot more but yeah you dont type the "mm" for example, you just type the number.

    So heres the code and i hope you can tell me whats wrong with it:

    Code:
    #include <iostream>
    int main()
    {
        using namespace std;
        int mynumber;
        cout << "What number do you want to make squared?" << endl;
        cin >> mynumber;
        cout << "Really dude? That number? your brain too small to make it squared yourself? fine than... heres your squared number: "
        mynumber = mynumber * mynumber;
        cout << mynumber;
        system("pause");
        return 0;
    }
    btw when i get the hang of c++ than i want to start making hacks, im currently learning from thenewboston at youtube but are there any better tuts? Since as far as i have seen he only shows how to make calcs and other stuff.







    LOL srry, just saw that i was missng a ; from the output, srry guys lol.
    Last edited by Ronon666; 06-14-2011 at 04:59 AM.



    Dont be a TOOL say Obamas cool.

  2. #2
    Vin¢e's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    9
    Reputation
    10
    Thanks
    1
    using namespace std;
    this should be placed outside the main() function, after #include <iostream>

  3. #3
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    Quote Originally Posted by Vin¢e View Post
    using namespace std;
    this should be placed outside the main() function, after #include <iostream>
    Stupidity Rules。。

    You can put it anywhere, and it will only be of use in that scope, but seeing how he only has a main, he can put it in Main And nothing will be wrong.

  4. #4
    Ronon666's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    What are you? A stalker?
    Posts
    122
    Reputation
    8
    Thanks
    46
    My Mood
    Bored
    O.o no duh that some of my programs failed. I was watching 4 years old video tuts..... well gonna look for some new ones.



    Dont be a TOOL say Obamas cool.

  5. #5
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    Quote Originally Posted by Ronon666 View Post
    O.o no duh that some of my programs failed. I was watching 4 years old video tuts..... well gonna look for some new ones.
    The last ANSI revision was 2003, the Videos should be fine。。

  6. #6
    cfsharp's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    196
    Reputation
    28
    Thanks
    23
    My Mood
    Cynical
    Code:
    cout << "Really dude? That number? your brain too small to make it squared yourself? fine than... heres your squared number: "
    You didn't put a semicolon on that line, other than that the code looks fine, though i wouldn't use system("pause"), it's not very efficient, i would use cin.get();

    and using namespace std; should be put at the top with your includes, even though like Virtual Void said, it is in scope for the main function, once you start making programs that have more than one function, you'll get out of scope errors, so putting it up at the top is a good convention.

    Good luck with your coding

    Programming languages i know:
    C# Advanced
    -Putting it down for now, to learn C-
    C++ Beginner
    C Beginner




  7. #7
    Ronon666's Avatar
    Join Date
    Jan 2011
    Gender
    male
    Location
    What are you? A stalker?
    Posts
    122
    Reputation
    8
    Thanks
    46
    My Mood
    Bored
    1. i made this by watching 4 year old video where the teacher was using old techiniques, on OP i posted like 10 sec after the real thread that i found the mistake lol.

    But anyways, i made new programs,(while looking at very recent tuts) most of them are under "My first c++ program!!!" in that thread. BTW lol, for my next prog i will use that cin.get(); and also, whos that in your sig xD?



    Dont be a TOOL say Obamas cool.

  8. #8
    Auxilium's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    深い碧の果てに
    Posts
    4,518
    Reputation
    445
    Thanks
    609
    My Mood
    Happy
    Quote Originally Posted by Ronon666 View Post
    1. i made this by watching 4 year old video where the teacher was using old techiniques, on OP i posted like 10 sec after the real thread that i found the mistake lol.

    But anyways, i made new programs,(while looking at very recent tuts) most of them are under "My first c++ program!!!" in that thread. BTW lol, for my next prog i will use that cin.get(); and also, whos that in your sig xD?
    and which technique is old?

  9. #9
    Minato_Nagato's Avatar
    Join Date
    Oct 2010
    Gender
    male
    Location
    That One Place... Yeah, That One!
    Posts
    204
    Reputation
    25
    Thanks
    20
    My Mood
    Amused
    arite, well, im still a beginner, but i saw that it didnt skip a line to say press any key to continue, so i fixed it, yeh...

    Code:
    #include <iostream>
    int main()
    {
        using namespace std;
        int mynumber;
        cout << "What number do you want to make squared?" << endl;
        cin >> mynumber;
        cout << "Really dude? That number? your brain too small to make it squared yourself? fine than... heres your squared number: ";
        mynumber = mynumber * mynumber;
        cout << mynumber << std::endl;
    	cin.get();
        return 0;
    }
    Last edited by Minato_Nagato; 06-16-2011 at 12:18 AM.
    My Build
    Intel i5-4670k 3.4 GHz
    Cooler Master Seidon 120mm Liquid Cooling(Push-pull)
    8 GB Gskill Ripjaws RAM
    Powercolor HD7950 3GB BOOST STATE(V5)
    Gigabyte-Z87-HD3 Motherboard
    Corsair 850w PSU
    Cooler Master Elite 431 Case
    2TB HDD


  10. #10
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    Quote Originally Posted by Minato_Nagato View Post
    arite, well, im still a beginner, but i saw that it didnt skip a line to say press any key to continue, so i fixed it, yeh...

    Code:
    #include <iostream>
    int main()
    {
        using namespace std;
        int mynumber;
        cout << "What number do you want to make squared?" << endl;
        cin >> mynumber;
        cout << "Really dude? That number? your brain too small to make it squared yourself? fine than... heres your squared number: ";
        mynumber = mynumber * mynumber;
        cout << mynumber << std::endl;
    	cin.get();
        return 0;
    }
    In the third to the last line, you wrote std::endl. You don't have to write it like that because it totally defeats the purpose of : using namespace std;. Instead the third to the last line should look like this:
    Code:
    cout<<mynumber<<endl;
    or you could do it like this:

    Code:
    cout<<mynumber<<"\n";
    Last edited by 258456; 06-16-2011 at 07:58 AM.