|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
i would like your opinion on my programs
ok so im learning c to program the robot with and i decided to intergrate my algebra 2 into my programming, so i made two programs in c. one is a program that deals with factorials and the other is one that deals with permutations.
so i wanted to get your guys opinion on the programs. i have included the source code and executable files in the zip file attaced to this post. btw it is 19kb Last edited by CmptrGk : 10-12-2004 at 09:21 PM. |
|
#2
|
|||||
|
|||||
|
Re: i would like your opinion on my programs
I tested your permutation code which compiled and ran without a hitch. I then reviewed your code and it is very good. However, you may want to add a filter to prevent someone from entering values that are too large.
|
|
#3
|
|||||
|
|||||
|
Re: i would like your opinion on my programs
ya i was thinking about the filter, i think i will add it later.
|
|
#4
|
||||||
|
||||||
|
Re: i would like your opinion on my programs
First of all, excellent work for someone just starting out with C. A few comments though to help make the transition from just playing with C to actually using it well:
First, unless you absolutely need to represent fractional numbers, you should always try avoid using doubles. They are _incredibly_ slow compared to ints. Since both factorial and permutations are purely integer functions, you would be much better off with simply using ints. Second, code modularity is very good thing. If you have some time, I'd definately try re-writing your programs so that factorial is a function that you can call from within your permutation program. This idea of re-usable code and breaking things into smaller functions is the key to really using C well. Third, global variables are a bad thing (unless you've got a darn good reason for using them). You can easily fix this by just moving your variable declarations to be inside the function where you want them. Anyways, as I said, nice work and good luck learning C! Rob |
|
#5
|
|||||
|
|||||
|
Re: i would like your opinion on my programs
the only reason i used the doubles was because the i wouldnt get any results for some larger numbers. i will also try to make seperate functions for each part (once i learn how to use them). and i did not know that you could instalise(is this the correct term) variables within functions.
|
|
#6
|
||||
|
||||
|
Re: i would like your opinion on my programs
Quote:
) a variable inside a function. This is greatly preferred by most authors, as it helps to keep everything modular and reusable. A variable declared inside a function, as foosFavorite is in this example...PHP Code:
In C, you have to declare all local variables at the beginning of the function. No other executed line can come before them; comments are fine, but no function calls or anything. C++ relaxes this rule, so if you're actually using a C++ compiler, it will let you get away with not having declarations at the beginning. Be warned though; the MPLAB compiler only accepts at the beginning. ![]() Last edited by Ryan M. : 10-14-2004 at 02:24 PM. |
|
#7
|
||||
|
||||
|
Re: i would like your opinion on my programs
Quote:
Also, I'm not 100% certain, but I believe it's faster if all your code is C, instead of C++ (this comes from extremely limited programming for Palm IIIs), but someone would have to confirm this, because I can't really remember the reasons or anything. |
|
#8
|
|||||
|
|||||
|
Re: i would like your opinion on my programs
Quote:
Some complilers will give you errors if you begin assigning values to variables and then try to declare another variable. Therefore, it is extremely important to declare all variables at the top of the function. |
|
#9
|
||||
|
||||
|
Re: i would like your opinion on my programs
Quote:
![]() |
|
#10
|
|||||
|
|||||
|
Re: i would like your opinion on my programs
thank you for giving me some input on my programs, with all of your suggestions i will probably be able to write better programs.
(i also cant spell at all) |
|
#11
|
||||||
|
||||||
|
Re: i would like your opinion on my programs
Quote:
-Rob |
|
#12
|
|||||
|
|||||
|
Re: i would like your opinion on my programs
Quote:
|
|
#13
|
|||||
|
|||||
|
Re: i would like your opinion on my programs
Quote:
|
|
#14
|
||||||
|
||||||
|
Re: i would like your opinion on my programs
"long int" is longhand for just long. long long is what Dillon wants, if his compiler supports it.
Also, while C++ is generally slower then C, it's only slower if you use C++ features. In Dillon's case, he named his file cpp, but didn't use anything not in C. |
|
#15
|
|||||
|
|||||
|
Re: i would like your opinion on my programs
well since im using DevC++ it automatically saves things in the .cpp extention. i think that it should probably support the long long variable.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| dash programs | suneel112 | Programming | 12 | 01-26-2005 02:44 PM |
| IFI's Serial Programs Doing Funny Stuff? | Ian W. | Programming | 4 | 03-18-2004 09:43 PM |
| Whats your honest opinion? | Sean | General Forum | 50 | 04-17-2003 09:05 PM |
| Dashboard programs and the char variable | Ian W. | Programming | 13 | 06-26-2002 02:07 AM |
| Dashboard programs | archiver | 2000 | 6 | 06-23-2002 11:10 PM |