QuestionWhat did i do wrong?

Posts 1–10 of 10 · Page 1 of 1
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.
using namespace std;
this should be placed outside the main() function, after #include <iostream>
Quote Originally Posted by Vine2 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.
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.
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。。
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
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?
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?
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;
}
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";
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us