using namespace std;
this should be placed outside the main() function, after #include <iostream>
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:
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.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; }
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.
using namespace std;
this should be placed outside the main() function, after #include <iostream>
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.
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();Code:cout << "Really dude? That number? your brain too small to make it squared yourself? fine than... heres your squared number: "
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
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.
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:
or you could do it like this:Code:cout<<mynumber<<endl;
Code:cout<<mynumber<<"\n";
Last edited by 258456; 06-16-2011 at 07:58 AM.