anyone a programmer or good at c++?

xscurry

New Member
Apr 1, 2005
39
0
0
Houston, Texas
I was just kidding. :icon_bigg

Higher level languages are great and definitely easier to work with for when resources are not a big concern. But, when resources are limited, a lower level language such as assembly can be very efficient. :icon_mrgr

I just graduated with my Computer Engineering degree with a focus on embedded systems. Programming is not my strong point. :)
 
Last edited:

outofstep

Senior Member
Mar 31, 2005
364
0
0
fwb
I'm using Dev C++, it's just the compiler as far as I know. But I don't know much, I'm a total C noob.
 

TobyCat

Member
Jul 14, 2006
470
0
16
Vancouver BC
Just a few comments on your code, just for future reference and assignments :)

as said by lagged: int main(int argc, char *argv[]). You don't need those parameters, your current program would be fine with int main(void). The parameters you specified argc=number of arguments and argv is an array of the actual arguments. So if you executed the program as "#> ./yourprog 80 90 100" then argc would be 4 and argv = {"yourprog", "80","90","100"}. No biggy, just so you know what's going on.

The double operator seems a little over kill. Modern computers are going to be OK with a little program like this that takes up way more space than it should, but once you advance further you should be aware of the memory sizes of your data types. int = 2^16 or 2 bytes of data. where a double, is well, double ;) 2^32 is HUGE. Sticking to integers would also fix your compile time warnings from your inadvertant casting of ints->double, double->ints etc.

system("PAUSE"); is a direct system call searching for a program PAUSE. I don't have pause in linux, so this doesn't work. generally if you'd like to pause a bit at the end of a program which is both windows/mac/linux compat you can use the sleep(int time) function.

your factorial function doesn't check conditions. Since you're using straight integers, not unsigned ints, i could pass in a negative #. You can't do factorial computation on negative #'s. Similiarly for power(). you CAN however raise something to a negative power, but if I were to pass in a negative # into the function it would just keep on computing the power until the programs heap/stack blew up :)

Other than that, it's not bad. Sounds like a good lil assignment as a primer to C. Of course, there isn't any C++ code in there other than the stream libraries and using cout instead of printf.

If you need any programming help you can always post here (looks like there are some programmers amongst us), and I'd love to help out a supra buddy in need :)
 

outofstep

Senior Member
Mar 31, 2005
364
0
0
fwb
If I chose to keep going the C++ route, I'll probably look into the other compilers (doing the EE thing, not the CS thing). As is I'm just using what we use in class.
 

TobyCat

Member
Jul 14, 2006
470
0
16
Vancouver BC
Take the leap into Linux then ;) gcc is ftw...you can get a port for windows but that's gross. Electrical Engineering eh? You're not gonna get away from programming at least for the first bit. Then, switch off to DSP and Circuit land and never touch programming again.
 

Kai

That Limey Bastard
Staff member
gcc? well, as a compiler, yeah, it's okay, but you have to be a hardcore programmer to want to use it - its not the easiest of things to use. I've used a few compilers and while I advocate the use of Visual C++, its for ease of use. There are faster and more efficient compilers out there, but if you're starting out in programming, VC++ is easier to get to use, and it's fairly forgiving, and not quite as cryptic when theres an error! :)
 

TobyCat

Member
Jul 14, 2006
470
0
16
Vancouver BC
gcc is more than OK ;)

Yeah, I agree that you want to use something a bit more "all-inclusive" when starting programming. IDE's are great for this - Visual C++, Visual Studio, XCode, etc. But when it really comes down to it, you're paying for the debugger aspect of the IDE, not the compiler.

But both are free to students, and VS .NET is pretty robust (even though I'm not a fan of the MS train ;)).
 

lagged

1991 1JZ
Mar 30, 2005
2,616
0
0
39
new rochelle
foreverpsycotic said:
looks neat and clean man, GJ. also noted your use of endl instead of '\n', too each his own.

actually, they are different.

std::endl sends a newline to the stream but also flushes the buffer. once you start learning how to take string input using getline() or similar you will see why you need to flush the buffer when taking input.

\n just sends a new line without doing anything else to the stream.


Kai said:
Aaaha. You might want to look at Visual C++ or Visual Studio suite for C++ programming. As i mentioned before, when it comes to debugging a program, it's SO much handier than anything else i've used.

if you ask most c programmers, they will probably tell you what i am about to tell you:

stay away from microsofts development environments. unless you are using .net and need it, if you are doing c++ youre only going to be making things harder for your self.

if youre using windows, dev++ or borlands IDE works very well.

if youre using linux, ive had a pretty good experience using anjuta (www.freshmeat.net)

TobyCat said:
system("PAUSE"); is a direct system call searching for a program PAUSE. I don't have pause in linux, so this doesn't work. generally if you'd like to pause a bit at the end of a program which is both windows/mac/linux compat you can use the sleep(int time) function.

you can also use getch() for behavior that is exactly the same as windows' pause command.

Kai said:
gcc? ....and not quite as cryptic when theres an error! :)

gcc's error messages are cryptic? how so? they are exactly the same error messages that one would see using any other compiler such as borland.

whats cryptic about it?