Welcome to the Forum Archive!

Years of conversation fill a ton of digital pages, and we've kept all of it accessible to browse or copy over. Whether you're looking for reveal articles for older champions, or the first time that Rammus rolled into an "OK" thread, or anything in between, you can find it here. When you're finished, check out the boards to join in the latest League of Legends discussions.

GO TO BOARDS


What is wrong with my C++ code???

1
Comment below rating threshold, click here to show it.

Brosama

Senior Member

02-01-2013

#include <iostream>
#include <string>
using namespace std;
int main();
{
cout<<"HI"<<endl;

return 0;
}

Visual Studios is saying there is errors with this


Comment below rating threshold, click here to show it.

I Know Better

Member

02-01-2013

Look at this symbol: ; This is the most fantastic punctuation mark ever, it's called a semicolon; when programming, it is an instruction terminator. When you type this:

#include <iostream>
#include <string>
using namespace std;
int main();
{
cout<<"HI"<<endl;

return 0;
}


You're using the semicolon to finish the main function before it has even done its stuff; typing this: "int main();" is the same as "int main() {}", it is an empty function. The problem is that this part:

{
cout<<"HI"<<endl;

return 0;
}


Makes no sense, because it doesn't actually belong to the main function, the main function already ended with the terminator. You need to remove the semicolon in order to make sure that this block actually is part of the main function and not a senseless block belonging to nowhere. This is how you make it work:

#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<"HI"<<endl;

return 0;
}


But then, you can always make it better; cleaner actually.


Comment below rating threshold, click here to show it.

JacobianMatrix

Senior Member

02-01-2013

Quote:
Brosama:
#include <iostream>
#include <string>
using namespace std;
int main();
{
cout<<"HI"<<endl;

return 0;
}

Visual Studios is saying there is errors with this


Quote:
Brosama:

int main();


There's your problem. Get rid of the semicolon.


Comment below rating threshold, click here to show it.

lukertin

Member

02-01-2013

Quote:
I Know Better:
Look at this symbol: ; This is the most fantastic punctuation mark ever, it's called a semicolon; when programming, it is an instruction terminator. When you type this:

#include <iostream>
#include <string>
using namespace std;
int main();
{
cout<<"HI"<<endl;

return 0;
}


You're using the semicolon to finish the main function before it has even done its stuff; typing this: "int main();" is the same as "int main() {}", it is an empty function. The problem is that this part:

{
cout<<"HI"<<endl;

return 0;
}


Makes no sense, because it doesn't actually belong to the main function, the main function already ended with the terminator. You need to remove the semicolon in order to make sure that this block actually is part of the main function and not a senseless block belonging to nowhere. This is how you make it work:

#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<"HI"<<endl;

return 0;
}


But then, you can always make it better; cleaner actually.


wowowow you are sooooo smart!!!!11


Comment below rating threshold, click here to show it.

Mere Intricacy

Senior Member

02-01-2013

Quote:
lukertin:
wowowow you are sooooo smart!!!!11

That awkward moment hen Dobs isn't being sarcastic.


Comment below rating threshold, click here to show it.

lukertin

Member

02-01-2013

It's been like...5 years since I wrote code, I think I stared at OP for about 30 min today trying to find what was wrong, considered making a troll post telling him to add *.h to the end of his #include and then decided not to.

don't tase me sis with your judgement


Comment below rating threshold, click here to show it.

Aliath

Senior Member

02-01-2013

lol


Comment below rating threshold, click here to show it.

vcadoda

Senior Member

02-01-2013

Quote:
lukertin:
It's been like...5 years since I wrote code, I think I stared at OP for about 30 min today trying to find what was wrong, considered making a troll post telling him to add *.h to the end of his #include and then decided not to.

don't tase me sis with your judgement

I dont see anything wrong with adding .h, just means you using c libraries now


Comment below rating threshold, click here to show it.

Umbasa

Senior Member

02-01-2013

semicolon on main function LOL. we all got trolled

you win this time op


1