Title: getting started with c++
666kennedy - February 6, 2007 08:14 PM (GMT)
sorry for possibly wasting peoples time, im very, i mean very new to this, i have always enjoyed programming and at uni we have started doing C++ now i want to get better and write stuff on my own, i will learn how to in uni but i would like to practise and try to add bits on my own time.
which brings me to my first point....
i have turbo C++ from borland, and i write in the program i just learned at uni that day and it didnt work, it was the first time i used it but it didnt recognise simple things like cout and cin! is it because turbo doesnt use it, or because i dont have the library of terms on my computer.
is there any programs, that i can get for free than i can program and when i run (compile, whatever) the program that debugger comes up so i can interact?
i would really appreciate the help with this one...
ps it will also be a very long time before i start posting code up!
biggoron - February 6, 2007 09:37 PM (GMT)
| QUOTE |
| ps it will also be a very long time before i start posting code up! |
Why? There's no shame in having messy code, especially if you are a beginner. Posting your code makes answering your questions much, much easier. In fact, it's pretty much impossible to tell what has gone wrong without it.
Assuming your first program was hello world it should be something like this:
| CODE |
#include <iostream>
int main(void) { std::cout << "Hello world!" << std::endl; return 0; } |
| QUOTE |
| is there any programs, that i can get for free than i can program and when i run (compile, whatever) the program that debugger comes up so i can interact? |
I tried VB once and it had one of those debugger majiggies. Maybe VC++ does too.
Ravotus - February 6, 2007 10:30 PM (GMT)
| QUOTE |
| Why? There's no shame in having messy code, especially if you are a beginner. |
Actually, I think it would be better to develop good coding habits early. Also, it is very annoying when you are trying to debug code that is unreadable. :P
Zaqufant - February 6, 2007 10:38 PM (GMT)
He didn't say anything about the habits, it's just that the syntax and stuff are messy and don't work. So please, post the code. And we'll do all we can to get it running.
Shonoby - February 6, 2007 10:48 PM (GMT)
Well, like bigron said y would it be long before u start posting, the first time i posted here i had a code that did not have errors. But it had something worse it had logical errors and a lot of them too. In this site we try to help each other, even if it is simple codes, like take this code for example:
| CODE |
int <iostream>
void main() { cout >> "Hello!' << endl; }
|
This code is very simple and as well as very incorrect.
OK well for ur first lesson, in the code above u see several things here they are:
- int <iostream>
- void main()
- cout && endl
- >>
- "Hello!'
- << endl;
- no return 0;
So the first thing here that is incorrect is 2 and 7. They seem different but can be solved with one edit. OK so the first thing is that in a program 'main()', should be 'int' and not made 'void' because 'main()' should return a value. Later on in ur programming life ( i guess ) u will come to know y 'main' has to return a value. For now just remember that returning a value should be 0 as of now, but later when u learn functions u will learn different. So 'main' should have been like so
| CODE |
int main() { ... return 0; }
|
Now in this code we can include 'return 0;', which is basically telling us that 'main' has terminated successfully. In the last code i mentioned that there was no 'return' value but i did not say y. The reason is that when a function ( 'main' in this case ) is declared 'void' it can not return a value so that is y i said that 'main' has to return a value.
Ok well now on to the other parts, in the first line of code has many errors. For first the programmer used 'cout' and 'endl;' without including 'std::'. But i think this programmer forgot to include two thing that are possible to do.
The first thing he forgot was to include 'std::' preceding a member for 'std::'.
But the second chose he could have done is include a 'using' function instead. Now what this does is this:
| CODE |
#include <iostream>
using std::cout; using std::endl; ......
|
Now what the 'using' keyword does is; that it enables the program to use 'cout' and 'endl' without including 'std::' preceding it. So this is somewhat easier and improves readability.
Now the other problems are done by mistake at times ( i know i do ). The first one is the preceding of the string of characters, like so:
Now as u can see this code it's 'cout' has the double arrow pointing to the left. What this means is that what ever is written right of it is seen out in the computers screen. How u pronounce 'cout' is like so 'c ( see ) out'. Now this keyword has to have the double arrows pointing to the left, if it was pointing to the right it would be incorrect and u would receive a compiler error. If the arrows point to the right that is what is received by keyword 'cin' which i don't want to get into now.
Now the next error is that the string of characters is:
Now this is incorrect because the operation ' is used to represent 1 character or a small phrase such as \n or \b and so on. So u can not use a ' to terminate something with more than a character.
So now the whole code fixed should look like so:
| CODE |
include <iostream>
using std::cout; // so cout does not need std:: everytime using std::endl; // same thing for this
int main() // main need to return value { // start main
cout << "Hello!" << endl; // cout is used to display hello and endl does what \n
return 0; // successfully terminated } // end main
|
Now u see how simple the code is but really how complex ( not really but the elements are complex ), which u will learn as u learn more of programming. So remember the simple codes are complex as well, and don't be shy of posting ur bad codes, cause as u can see i like to explain thoroughly. LOL so don't be shy of coming here for help.
Rmstn1580 - February 6, 2007 11:08 PM (GMT)
Dev-C++. Best compiler in the world.
www.BloodShed.net
Shonoby - February 6, 2007 11:18 PM (GMT)
Well, i guess that is good but i don't like doing that:
| CODE |
systen( "PASUE" ); return EXIT_SUCCESS;
|
But my compiler does that automatically MUHAHHA, i got
'Microsoft Visual C++ 6.0 Beginners Edition' yea it came with my book.
666kennedy - February 6, 2007 11:57 PM (GMT)
hey its not that im worried about the code being crap, its just that i get all my code checked by lecturers and everything, and i dont see the point in putting basic stuff up, anyway its not the actual code thats giving me the trouble, its the fact that i have turbo c++ on my computer, and when i use commands such as cout << and stuff it comes up with an error message that says it doesnt recognise it! i will try that dev-C++ though.
thanks very much for your help so far
Shonoby - February 7, 2007 12:01 AM (GMT)
Yea, i know what u mean about turbo C++ i have used it before and it happened to me so i just stayed with my compiler.I really dont like turbo C++ to me it's like using nothing.
Mephisto - February 7, 2007 12:51 AM (GMT)
Sounds like you forgot to include
#include <iostream>
to me.
| CODE |
#include <iostream> #include <cstdlib> using namespace std;
int main() { cout << "********************************************************" << endl; cout << "Hello World" << endl; cout << "********************************************************" << endl; system("pause"); return 0; } //end of main
|
Good ol' Hello World.
Zaqufant - February 7, 2007 02:07 AM (GMT)
Either that or you forgot to tell the namespace. To do this you have a few options...
| CODE |
| using namespace std; |
I use this one, this one just tells the compiler to use everything thats in the std namespcace.
option 2
| CODE |
#include<iostream>
using std::cout; using std::cin;
|
this is the namespace and the object you would like to use seperated by a double colon. This one is the one you probably should use because it doesn't have to keep track of all the unnecesarry objects that you are never going to use in the program.
and third one is:
| CODE |
#include<iostream>
int main() { std::cout << "I love you JENNAY" << std::endl; return 0; }
|
This one you only access the objects where you need them. This one is just a waste of typeing if you ask me. I have never used it.
And as you can tell, we love to help people out that are doing the thing that we all love here: programming. So just ask any questions. And if someone gives you some shit (that I may sometime) ignore them.
666kennedy - February 7, 2007 07:29 PM (GMT)
hey thanks for the help, i have dev- C++ and its fine, works with the 2 programs ive learned so far, im on a new one now however, and i am coping fine with what the instructions from my notes are saying, (bareing in mind that i have the lab on a monday with ppl who are there to help) but i have got to a point where it is asking for a variable declaration, instead of the const ones ive been making so far...
here is the code for the program im editing with the varible stuff...
int main (void)
{
const float PI = 3.14159265;
const float RADIUS = 2.0;
cout << endl << " the are of the circle is " << ( PI * RADIUS * RADIUS);
getch();
return 0;
}
i know this program isnt very useful, and u have to edit and compile every time u want a new area...
but it then asks me to make it more flexible by modifying the declaration of the float constant RADIUS and replace it with a variable declaration (naming the variable "radius"). then set the radius to 2.0 usign a seperate assigment statement in the body of the program. this is not as far as adding "cin" however. i hope you can help!