Computer Science Canada Answer wont display right |
Author: | JR [ Tue Oct 19, 2004 10:27 pm ] | ||
Post subject: | Answer wont display right | ||
this program calculates the points the user got from the questions, well a part of it. now when i putput the points i get some strange number which is wrong, how do i make it output the right nunbmer at the end of the 5 questions when it calculated all the points?
|
Author: | Andy [ Wed Oct 20, 2004 3:02 pm ] |
Post subject: | |
u have to define points to 0... if u dont, the program will just give you what ever is at that specific memory allocation at that time |
Author: | JR [ Thu Oct 21, 2004 6:14 am ] |
Post subject: | |
lol i misseds that one thx |
Author: | JHanson90 [ Fri Oct 22, 2004 11:20 pm ] | ||
Post subject: | |||
Since the title of this topic applies to the problem that I'm having, I might as well post this in here. I'm learning C (note for the careless reader: not C++), and I'm in the second chapter of a book about it. My exercise is to write a program that will ask the user for a number, and the program returns all of that number's factors. It compiles fine. But at run-time, I encounter an error that reads "Floating point exception" when it gets to the 'for' loop part. I tried to Google it, but I couldn't understand much of what was said being a noob to C. Here's the program:
|
Author: | wtd [ Sat Oct 23, 2004 3:35 am ] | ||||||
Post subject: | |||||||
Which compiler are you using?
When you divide by i, the first time through the loop, you're dividing by zero. Division by zero does bad bad things. Since 0 isn't a factor of anything, I suggest starting with:
And a few other modifications:
|
Author: | Andy [ Sat Oct 23, 2004 9:55 am ] |
Post subject: | |
yea thats the problem.. btw, wtd what does %d do? im not too familiar wit C.. only c++ |
Author: | wtd [ Sat Oct 23, 2004 2:14 pm ] |
Post subject: | |
%d is a format specifier. http://www.dgp.utoronto.ca/~ajr/209/notes/printf.html |
Author: | Andy [ Sat Oct 23, 2004 5:11 pm ] |
Post subject: | |
OOooo... thats nice.. thx man |
Author: | wtd [ Sat Oct 23, 2004 5:50 pm ] | ||||||||
Post subject: | |||||||||
Conveniently, those standards are implemented by many languages. O'Caml:
Java 1.5/5.0:
Perl:
Ruby:
|
Author: | JHanson90 [ Sat Oct 23, 2004 11:00 pm ] | ||
Post subject: | |||
wtd wrote: What compiler are you using? The GNU Compiler Collection (commonly abbreviated as "GCC").
wtd wrote: When you divide by i, the first time through the loop, you're dividing by zero. Division by zero does bad bad things. Ah, so really just a math error (dumb of me not to remember that you can't divide by 0). Thanks.
wtd wrote: And a few other modifications:
Hmm, are fprintf() and fscanf() more efficient or something?
|
Author: | wtd [ Sat Oct 23, 2004 11:45 pm ] |
Post subject: | |
JHanson90 wrote: Hmm, are fprintf() and fscanf() more efficient or something?
Don't know... Just showing off. ![]() |
Author: | JHanson90 [ Sun Oct 24, 2004 8:02 pm ] |
Post subject: | |
wtd wrote: JHanson90 wrote: Hmm, are fprintf() and fscanf() more efficient or something?
Don't know... Just showing off. ![]() Yes, I suppose that that's the main job of a consultant. ![]() |
Author: | wtd [ Sun Oct 24, 2004 9:18 pm ] |
Post subject: | |
He begins to understand... |