Forum: C Sep 7th, 2008 |
| Replies: 7 Views: 683 You still have to fix your initialization of the done[15] element, but the seg fault is gone since you've now set aside 16 elements. As far as the logic goes, it makes sense and it seems like it... |
Forum: C Sep 6th, 2008 |
| Replies: 7 Views: 683 Your done array has 15 elements and thus can handle indexes from 0 to 14. val has a potential range of 0 - 15. You have this on line 15:
if(!done[val])
which will be this if val is 15:
... |
Forum: C Aug 4th, 2008 |
| Replies: 5 Views: 1,170 "It still doesn't work" isn't descriptive enough. It does work, to a point, but you are getting repeats. If x and y both flunk the primality test, n1 and n2 are unchanged and are printed again. ... |
Forum: C Aug 4th, 2008 |
| Replies: 5 Views: 1,170 Lines 13 and 19. Make sure you have the larger number to the left of the % sign and the smaller number to the right of the % sign.
Lines 15 and 21 don't seem to do anything. x already equals x... |
Forum: C Aug 4th, 2008 |
| Replies: 5 Views: 1,170 I'm not sure why you have a nested loop in this program. I don't think you need one. I think I would create a function that returns true or false (1 or 0) based on whether a number is prime. ... |
Forum: C Jul 25th, 2008 |
| Replies: 8 Views: 1,062 I question whether you want to #define this function instead of just declaring it at the top. Try replacing
#define GCD();
with this: |
Forum: C Jul 25th, 2008 |
| Replies: 15 Views: 1,410 First, make sure you are using a C compiler if this is a C program and make sure the extension at the end of the file is .c, not .cpp. If this is a C++ program, you're in the wrong forum. Assuming... |
Forum: C Jul 25th, 2008 |
| Replies: 15 Views: 1,410 Ah, OK, you are referring to these lines, perhaps?
x = ((-b - d)/(2.0*a));
y = ((-b + d)/(2.0*a));
I get a warning in C++ (not an error) which says "Warning: Converting from 'int' to... |
Forum: C Jul 25th, 2008 |
| Replies: 15 Views: 1,410 You have that backwards. These lines:
#include <iostream>
using namespace std;
are fine with a C++ compiler, but cannot be used with a C compiler. |
Forum: C Jul 25th, 2008 |
| Replies: 15 Views: 1,410 iostream isn't in C. I think you have quotes where you want <> in your #include for math.h, and you can't use "using namespace std" in C. Maybe you're not using a C compiler.
The problem with... |
Forum: C May 29th, 2008 |
| Replies: 5 Views: 661 I'm guessing you have a problem in line 4 when you declare your 2-dimensional array:
num[2][n];
At this point n is uninitialized. You don't get a value for n till line 7 so it's impossible to... |
Forum: C Mar 2nd, 2008 |
| Replies: 5 Views: 1,950 The window will close when the program is done. It's possible that the program is running correctly and displaying what you want, but is simply closing faster than your eye can register. Check out... |
Forum: C Mar 1st, 2008 |
| Replies: 19 Views: 1,361 I would get rid of the grandtotal FUNCTION and go back to a grandtotal VARIABLE. I would initialize this variable called grandtotal to 0.0 in the very beginning (before any loop). I think you have... |
Forum: C Mar 1st, 2008 |
| Replies: 19 Views: 1,361 Line 41:
multtotal += total;
multtotal has not been initialized and variable total does not exist. |
Forum: C Mar 1st, 2008 |
| Replies: 19 Views: 1,361 See my earlier post in the C++ section:
http://www.daniweb.com/forums/post549484-2.html
It applies to the C language as well and it looks like you still have a lot of the same code that will give... |
Forum: C Feb 27th, 2008 |
| Replies: 5 Views: 2,168 You should not have a condition after the "else" statement. Only "if" and "else if" statements should have conditions. Try changing it to this:
else
{
printf("The largest value is %f.",... |
Forum: C Feb 27th, 2008 |
| Replies: 5 Views: 2,168 These are two recent threads with similar topics. They're from the C++ forum, but the logic is the same in C.
http://www.daniweb.com/forums/thread111048.html... |
Forum: C Feb 9th, 2008 |
| Replies: 4 Views: 1,666 How about setting up a counter, initialize the counter to 0, then using a while loop? Each pass through the while loop could calculate the integer mod 10. If that result is 2 (or whatever digit... |
Forum: C Feb 8th, 2008 |
| Replies: 8 Views: 865 Well at the very least you have a problem in line 63 in your original code:
for(i=0;(ch!=' ') || (ch!='\n');i++)
The above criteria will always be true. You have an OR (||). You need an... |
Forum: C Feb 8th, 2008 |
| Replies: 8 Views: 865 What are the contents of the txt.txt file? |
Forum: C Feb 3rd, 2008 |
| Replies: 5 Views: 766 Well as far as I can tell you are using the variable x but never initializing it and never changing it so it's functioning more like a constant with unknown value. You are reading data into a[x],... |