Programming

dragon2309

P.I Dragon
Right, as there is no programming section on here... I have to post it here.

Im studying COMPUTING in school for AS Level, 2 years of learning C++ and making progs. Anyhoo, i need a editor and compiler all in one, but dont know what to get, i want a really decent one, but preferably free. I know of Vim and gVim, they arent too good, i aslo know of Sharp Develop C++ but i dont like that one too much, anyone know of a C++ editor AND compiler.

It has to be a compiler aswell, thanks.
 
well original question is orted so to save space it hought i would add to this thread instead of making a new one lol.

Anyone know whats wrong here, ive debuged quite a lot, whittled it down to just a few compile errors now. But i really have no idea whats wrong with it. ANYONE!!

codeerror6pq.jpg

anyone?
 
my college classes require me to use g++ in linux. however in the past i have used dev c++ which is free and codewarrior which is really expensive.
 
semi colons are lin terminators so terminate some lines (I don't like the way your code is layed out so I made it go my way). In your code add semi colons after first = "2";, second = "5"; and result = first + second;
Code:
#include <stdio.h>
int main(){
int first;
int second;
int result;

first = 2; // if you want the ascii value of 2 use "2"
second = 5; //same deal as above

result = first + second;

printf ("%d", result);

return 0;
}
 
Last edited:
not really, I just always group things in a way that makes sense to me. I forgot to have a return 0; at the end of my code before the closing } (not that it doesn't work but it's not entirely correct)
 
the return 0 part, is that to hold the cmd applet open when its finished, because it closes automatically. I know this is because its how indows habdles it, and i know theres a simple way to make it stay open indefinately, do you know how to do that?
 
Hi.

You can use "system("PAUSE");"

like so:
Code:
#include <stdio.h>
int main(){
int first;
int second;
int result;

first = 2; // if you want the ascii value of 2 use "2"
second = 5; //same deal as above

result = first + second;

printf ("%d", result);

system("PAUSE");
return 0;
}
 
Seems you've got it coverd already but, I should have mentioned, you will have to use #include <stdlib.h> for system("") to work.

EDIT: Also, system("") can be used to run any cmd.exe command. Like system("CLS") will clear the screen .ect.

If you would like to know a way to make your program return to the start after system("PAUSE") instead of just exiting let just let me know.
 
Last edited:
when you say "return to the start, do you mean the start of the program, and run it all again, or back to the deault command line lcation?

And yes, i realised that i had to include cstlib for system commands to work properly, realised that after a lot of times with it not compiling.
 
dragon2309 said:
the return 0 part, is that to hold the cmd applet open when its finished

No return 0 is there because main() was declared as a int function. All int function must return something. It can be useful for making the program exit on a error. As soon as the function return something the function is over.

If you wanted to get rid of the return 0 then you can declare main as Void main() instead of int main(). Void functions do not return anything.
 
ok, thanks, thats helped a lot. As you can prbably tell im not at all very good at this C++ yet, im learning it for A-Level Computing, i think im gettin the jist of it now though. Most small programs are pretty much the same in terms of what they start and end with, you just change the function.
 
you should avoid using system calls as much as you can. usually there is a c/c++ function that does the same as a system command.
 
any reason for avoiding system commands, they seem to work fine, any examples of equivalent c/c++ code for them, like wshat is SYSTEM(pause) in c++ etc...
 
you can use printf("Press Any Key to Continue...");getch(); to act like a system pause. basically you want to avoid going to the shell whenever possible because you can't always predict how it will behave.
 
dragon2309 did you get that compiler? because I really wanna do some programming in C and I really got to do it because I can't find an editor and compiler. I was gonna install Linux but I wanna wait until I've made my new computer and it might take a while.
 
Back
Top