why does this simple function not work

So I'm just trying to learn C++ and Visual Studio is apparently not wanting to work for me.
What is wrong with this code?

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
	if (1>3) {
		cout << "Timmy is cool"
	}


	return 0;

}
NEVERMIND; I forgot to add a semi colon.

For C++ experts out there, did you make stupid mistakes like this when you first started?

And also, how long did it take you to get familiar with C++

C++ is the first language I am learning, I have basic knowledge of HTML, PHP and stuff like that but C++ is the first language I'm going to be dedicating time into
It has nothing to do with Visual Studio. Your code just doesn't make any sense.
How can 1 > 3 ??????????
well....considering "1 > 3" is a boolean checking it makes perfect sense because it return values (in this case, it is false ) although I see no purpose of the if being there
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

int main()
{
	if (1>3) {
		cout << "Timmy is cool"
	}
        else {
            cout << "1 is NOT greater than 3\n";
       }

	return 0;

}
No, 1>3 was just a test and I was going to make an else statement
It said 1 failed, it didn't run at all.

Also I'm now trying to make a hello world, and it also says 1 failed?
1
2
3
4
5
6
7
8
 #include <iostream>
using namespace std;

int main()
{
	cout << "yo\n";
	return 0;
} 

how does that not make sense?
Last edited on
yes, every expert made mistakes getting started. Mismatched {}s. Failed to include the header for the needed calls. for(); (does nothing N times because of the do-nothing ; on the end!). if(); (conditionally does nothing, then does the next block every time, ; again error). Everyone has done it. Most of us still do it once in a while, but we know how to find it fast when we goof due to experience. And compilers warn about more of this stuff than they once did.


It takes a couple of years to get pretty good at c++ and more like 5 years to be a grand master. And the language keeps changing and growing, which is another frustration... put it down for just a few years and its not the same when you come back (suffering this issue myself!)

The good news is that c++ pulls in a lot of near freebies. Knowing it, you can pick up java, c#, python, and several other languages that were based off c++ or C syntax. I can read and edit all these, without knowing them, with just my C++ background + google.

Don't worry about the comment... your first couple of programs don't have to make a lot of sense. Most early programs are contrived examples and dumb problems that you can solve with 1/10 the code later once you know how. They are just there to teach you some things.

We need your error messages if you have something not working. Your second one looks ok, but what did it say or do?




@jonnin
yeah, it just says
error C2143: syntax error: missing ';' before '}'
1>Done building project "Learning C++.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
also: I fixed the one above but

fatal error LNK1169: one or more multiply defined symbols found
And what does the code look like now?
1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;

int main()
{
	cout << "yo\n";
	return 0;
}
That code compiles and runs.

http://ideone.com/WVhMJ1

Whatever your linker is complaining about, it's not this code. I expect you're trying to build some other code. Perhaps you chose the wrong kind of project. Visual Studio is not a great IDE for a beginner.
Last edited on
be sure you did a rebuild all in your project. The other options can leave junk from earlier mistakes (its an efficiency thing, if you have a huge project, and only 1 file in 30 changed, it does not need to check the other 29 in every situation ...)
Last edited on
Topic archived. No new replies allowed.