![]() |
|
#11
|
|||
|
|||
|
Quote:
You are given a test case. Did you run it? What did you get? I feel that the best way to debug a program is to feed it data and see if it gives expected results. (The program listing of your previous post has error(s) that prevent it from compiling.) Before you debug the calculations, I think you should make sure that the calculation routine is getting the data that you expect it to have. So... put printf(), showing the values of the arguments num1, num2, etc., in the main program just before calling the encrypt/decrypt function. Then, at the beginning of encrypt(), put a printf showing the value if the argument that it was called with, and put a printf() just before the return statement, showing the return value. This is called the "top-down" approach. If you prefer the bottom-up approach, then make a separate program that only has main(), encrypt() and check_div(). In your main program set e, n, d and num1 to the values that you want (no user input required for this test program). Call encrypt and see what the return value is. Does it match the test case? If you can't see what the problem is, show us what you did, what you expected to get, and what you got. It won't help you very much for us to debug your program, but we will be more than happy to try to help you understand how to debug and to understand what's happening in a program. Either the top-down or the bottom-up approach is viable, pick one. Regards, Dave |
|||
|
#12
|
||||
|
||||
|
I see we've been wasting our time. After all this you
1) did not remove any scanf()functions 2) added a function that is not defined: fflush(stdin); The C standard states that fflush() is undefined for input. You therefore should not use it because it is not guaranteed to work. If you're instructor is teaching you to flush stdin, I highly question his abilities. He is teaching very bad habits and bad programming techniques, all of which you will find hard to break and when they don't work, you will spend days trying to figure out why. __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [TUTORIAL] Calling an external program in C (Linux) | dsmith | C Programming Language | 4 | 22-Apr-2005 14:30 |
| Anyone can write a program code for this??? | chriskan76 | C Programming Language | 1 | 19-Oct-2004 21:25 |
| Need help with a C program (Long) | McFury | C Programming Language | 3 | 29-Apr-2004 21:06 |
| error during program | rjd72285 | C++ Forum | 0 | 11-Nov-2003 19:49 |
| one program access another? | dgoulston | C++ Forum | 1 | 07-Oct-2003 12:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The