PDA

View Full Version : Anyone know C++?


Hotwheelz
01-17-2009, 10:07 PM
I'm trying to learn C++ and this code won't compile. Anyone know why?

#insert <iostream><iostream>
using namespace std
void main()
{
bool P = true
cout << "P = " << P << endl;
cout << "Not P = " << :P << endl;
P = !P;
cout << "P = " << P << endl;
cout << "Not P = " << !P << endl;
return 0;

}
(#insert <iostream> < iostream > is there, just won't show up here.)
</iostream></iostream></iostream>

frerottenextelway
01-17-2009, 10:14 PM
Not me. I'm sure Spider can help you once he sees this.

Taco John
01-17-2009, 10:19 PM
My guess:

The line: bool P = true

Doesn't there need to be a ; at the end of that?

Hotwheelz
01-17-2009, 10:21 PM
My guess:

The line: bool P = true

Doesn't there need to be a ; at the end of that?

Tried it. Still no go.

Taco John
01-17-2009, 10:23 PM
Sorry. It's been years since I looked at C++. I thought that might be a quick solution - a common error. Apparently not.

CEH
01-17-2009, 10:24 PM
#insert
using namespace std
void main()
{
bool P = true
cout << "P = " << P << endl;
cout << "Not P = " << :P << endl;
P = !P;
cout << "P = " << P << endl;
cout << "Not P = " << !P << endl;
return 0;

}
:P does not exist. Should be !P (not P)
Yes also try the ; after the declartion of P

Hotwheelz
01-17-2009, 10:28 PM
cout << "Not P = " << :P << endl;

:P does not exist. Should be !P
Yes also try the ; after the declartion of P

No go. Could it be the compiler?

CEH
01-17-2009, 10:32 PM
No go. Could it be the compiler?

What does the error message say?

Hotwheelz
01-17-2009, 10:39 PM
What does the error message say?
.

1>Compiling...
1>main.cpp
1>d:\documents\visual studio 2008\projects\poop\poop\main.cpp(3) : error C2144: syntax error : 'void' should be preceded by ';'
1>d:\documents\visual studio 2008\projects\poop\poop\main.cpp(6) : error C2146: syntax error : missing ';' before identifier 'cout'
1>d:\documents\visual studio 2008\projects\poop\poop\main.cpp(7) : error C2059: syntax error : ':'
1>d:\documents\visual studio 2008\projects\poop\poop\main.cpp(11) : error C2562: 'main' : 'void' function returning a value
1> d:\documents\visual studio 2008\projects\poop\poop\main.cpp(3) : see declaration of 'main'
1>Build log was saved at "file://d:\Documents\Visual Studio 2008\Projects\poop\poop\Debug\BuildLog.htm"
1>poop - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

CEH
01-17-2009, 10:47 PM
.

1>Compiling...
1>main.cpp
1>d:\documents\visual studio 2008\projects\poop\poop\main.cpp(3) : error C2144: syntax error : 'void' should be preceded by ';'
using namespace std;
1>d:\documents\visual studio 2008\projects\poop\poop\main.cpp(6) : error C2146: syntax error : missing ';' before identifier 'cout'

Add the ; after the bool P declaration

1>d:\documents\visual studio 2008\projects\poop\poop\main.cpp(7) : error C2059: syntax error : ':'

colon P does not exist. You meant to type !P

1>d:\documents\visual studio 2008\projects\poop\poop\main.cpp(11) : error C2562: 'main' : 'void' function returning a value

do not return 0

1> d:\documents\visual studio 2008\projects\poop\poop\main.cpp(3) : see declaration of 'main'
1>Build log was saved at "file://d:\Documents\Visual Studio 2008\Projects\poop\poop\Debug\BuildLog.htm"
1>poop - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

using namespace std;
void main()
{
bool P = true;
cout << "P = " << P << endl;
cout << "Not P = " << !P << endl;
P = !P;
cout << "P = " << P << endl;
cout << "Not P = " << !P << endl;
// return 0;

}

JLesSPE
01-17-2009, 10:52 PM
I always declared my main as an int. int main()

because you're returning a number 0 at the end. if you declare something a void i dont think you can assign it an integer value. i may be wrong on that, it's just a guess. As mentioned before, you need to finish off your variable declaration with a ";" and then the 3rd line of your main function should be "!P" instead of ": P"

Hotwheelz
01-17-2009, 11:06 PM
Got it, thanks guys.

]
#insert <iostream>
using namespace std
void main()
{
bool P = true
cout << "P = " << P << endl;
cout << "Not P = " << :P << endl;
P = !P;
cout << "P = " << P << endl;
cout << "Not P = " << !P << endl;

}

Wes Mantooth
01-17-2009, 11:47 PM
I always declared my main as an int. int main()

because you're returning a number 0 at the end. if you declare something a void i dont think you can assign it an integer value. i may be wrong on that, it's just a guess. As mentioned before, you need to finish off your variable declaration with a ";" and then the 3rd line of your main function should be "!P" instead of ": P"


Correct. Voids have no return value.

bronco610
01-18-2009, 02:18 AM
Damn!!! I have to take that this semester. Now I'm worried. That made as much sense to me as my second wife:dummy:

Hotwheelz
01-18-2009, 03:32 AM
Damn!!! I have to take that this semester. Now I'm worried. That made as much sense to me as my second wife:dummy:

http://www.xoax.net

MechanicalBull
01-18-2009, 07:27 AM
All this brings back memories. I haven't fooled around with c++ in years.

Rock Chalk
01-18-2009, 07:56 AM
All this brings back memories. I haven't fooled around with c++ in years.

+1

hades
01-18-2009, 08:02 AM
All this brings back memories. I haven't fooled around with c++ in years.


No kidding. I bought the "Teach Yourself C in 21 Days" book several years ago, and after day 6, I put the book away and never looked at it again. Gimme shell scripting, or even Perl (very little Perl tho) any day!

Broncoman13
01-18-2009, 08:10 AM
Meh, go figure out the Space/Time Continuum, build a better version of the Flux Capacitor and then we'll talk... until then, you guys are just nerds. 'Specially that Gayhawk cat!


;D

WolfpackGuy
01-18-2009, 09:17 AM
I don't know C++, but one thing I learned in college was:
FORTRAN=chit

Wes Mantooth
01-18-2009, 09:23 AM
I don't know C++, but one thing I learned in college was:
FORTRAN=chit

You have now dated yourself!

Abqbronco
01-18-2009, 09:35 AM
I took c++ last semester. It has changed my career path forever. That was the hardest class I ever dropped.

MechanicalBull
01-18-2009, 10:35 AM
I took c++ last semester. It has changed my career path forever. That was the hardest class I ever dropped.

I took level 1 and 2 c++ along with VB, Java, Unix and was thinking about continuing the programming field but started to like the hardware more than software/programming and haven't coded in awhile.

TonyR
01-18-2009, 12:06 PM
That made as much sense to me as my second wife

Your first mistake was trying to make sense of a woman...

Rock Chalk
01-18-2009, 04:55 PM
I don't know C++, but one thing I learned in college was:
FORTRAN=chit

Are you 60 or something?

Fortran...thats ****ing old skool.

C++ isnt young but then, its still widely used on the archaic software model.

If you arent using an online capable language these days, (Perl, PHP, any .NET language like C# or ASP.NET (not classic ASP), or cold fusion) you are in the dark ages.

C++ is a good learning tool though and if you intend on building software its OK, though Python is taking more and more prominence in that field.

broncosteven
01-18-2009, 04:58 PM
No kidding. I bought the "Teach Yourself C in 21 Days" book several years ago, and after day 6, I put the book away and never looked at it again. Gimme shell scripting, or even Perl (very little Perl tho) any day!

I have that book.

I tried the book alone, got to linked lists and never figured it out.

I then took the class thinking I would get the same class as my future wife but that didn't happen.

We did some study sessions and all she wanted to so was study and I wanted to fool around.

I got a C the 1st time but still had trouble with link lists. The wife got an A. I finally got her a few years later.

Rock Chalk
01-18-2009, 05:00 PM
Everyone who thinks C++ is hard should change their mind on career choices.

C++ is for logical minds with logical thought processes. If you dont get it, you will never get any language. Its not hard to learn if you are destined to be a programmer. Thats the benefit of C++. Its required and it weeds out the wannabee's.

CEH
01-18-2009, 05:03 PM
Are you 60 or something?

Fortran...thats ****ing old skool.

C++ isnt young but then, its still widely used on the archaic software model.

If you arent using an online capable language these days, (Perl, PHP, any .NET language like C# or ASP.NET (not classic ASP), or cold fusion) you are in the dark ages.

C++ is a good learning tool though and if you intend on building software its OK, though Python is taking more and more prominence in that field.

The lanague is really not where the value is. It's the object oriented functionality of the language you want to learn. That and multi-tiered architecture.

Once you have that understanding and know the syntax of a language like C++ its simple to move to .Net or Java or AJAX

Using C++ you want to think in terms of nouns and real world objects like messageboard, thread, post, user, user profile etc

broncosteven
01-18-2009, 05:05 PM
The lanague is really not where the value is. It's the object oriented functionality of the language you want to learn. That and multi-tiered architecture.

Once you have that understanding and know the syntax of a language like C++ its simple to move to .Net or Java or AJAX

I agree that I can read most code because of the time I spent on C.

Rock Chalk
01-18-2009, 05:16 PM
The lanague is really not where the value is. It's the object oriented functionality of the language you want to learn. That and multi-tiered architecture.

Once you have that understanding and know the syntax of a language like C++ its simple to move to .Net or Java or AJAX

Using C++ you want to think in terms of nouns and real world objects like messageboard, thread, post, user, user profile etc

But it starts with the required courses. If you think they are hard, you are in the wrong field.

THats not a knock on anyone. I thought A&P was hard, hence I didnt go into the medical field. If you dont have a mind for it, then you will never "get it". The OOP of it comes with the mind of a programmer. Understanding object classes is the key, I agree with you. I focus mostly on PHP but with the OOP aspects of PHP 5.0 and what I learned of OOP in college and on my own, it is EASY for me to switch to most other languages. Syntax is all you have to learn at that point...and built in functions but those are easy. But if you dont get the structure of programming and how it works, or if it comes difficult to you, then it is the wrong field of study.

Prgramming is for mathematical, logical minds. If you don't have a mind that thinks in those terms, it will NEVER be easy for you and you will NEVER be a good programmer.

cbs1177
01-18-2009, 05:20 PM
My C++ teacher sounded like kermit the frog. Ugh hated it. Not enough patience for a missing comma

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
Brian W. Kernighan

I cheated and only wrote for what the prof. wanted. and knew what he tested.

CEH
01-18-2009, 05:27 PM
My C++ teacher sounded like kermit the frog. Ugh hated it. Not enough patience for a missing comma

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
Brian W. Kernighan

I cheated and only wrote for what the prof. wanted. and knew what he tested.


I got paid by the number of bugs I fixed so I wrote myself a minivan - Dilbert

Rock Chalk
01-18-2009, 05:32 PM
Debugging is like 90% of the actual work you do in the professional world.

I love debugging. If I didnt love debugging I probably wouldnt be in the field. I rarely get the chance to write code from scratch, what I usually have to do is make changes to existing code without breaking what does work and make what needs to work work within an existing structure.

Generally not easy when most of the code is written by some overly complex Indian (dot not feather) programmer trying to just show off what he knows without regards to what is actually needed for the project.