Change Forum... Civil Aviation Travel, Polls & Prefs Tech/Ops Aviation Hobby Aviation Photography Photography Feedback Trip Reports Military Av & Space Non-Aviation Site Related LIVE Chat My Starred Topics | Profile | New Topic | Forum Index | Help | Search
 Someone Debug My C Source Code
 Lehpron From United States of America, joined Jul 2001, 7028 posts, RR: 19Posted Tue Nov 5 2002 05:36:58 UTC (13 years 3 months 1 week 1 day 12 hours ago) and read 1415 times:

 Our assignment (I admit to procrastinating) is due by midnight, which is in 2.5 hours. I already tried looking for examples online but none was found. Our assignment was in the C programming language, and we were to find the root of a quadratic function, Ax2 + Bx + C = 0, and thier corresponding slopes. The program is supposed to terminate when 'A', 'B' and 'C' equals zero, but instead it terminates at just 'A' = 0. This is my code: #include #include float flt_a; float flt_b; float flt_c; int int_x1; int int_x2; int int_m1; int int_m2; int int_root; void main () { do { printf("For formula reading Ax^2 + Bx + C = 0,n"); printf("n"); printf("Enter first coefficent, A:n"); scanf("%f", & flt_a); printf("n"); printf("Enter first coefficent, B:n"); scanf("%f", & flt_b); printf("n"); printf("Enter first coefficent, C:n"); scanf("%f", & flt_c); printf("n"); if (flt_a != 0.0 || flt_b != 0.0 || flt_c != 0.0) { if (flt_b * flt_b - 4 * flt_a * flt_c < 0.0) { int_root = 0; } else { int_root = 2; int_x1=(-flt_b + sqrt((flt_b * flt_b)- 4*flt_a*flt_c))/(2*flt_a); int_x2=(-flt_b - sqrt((flt_b * flt_b)- 4*flt_a*flt_c))/(2*flt_a); int_m1= 2 * flt_a * int_x1 + flt_b; int_m2= 2 * flt_a * int_x2 + flt_b; } } else { if (flt_a == 0) { int_root= 1; int_x1=(-flt_c / flt_b); int_m1= flt_b; } else { int_root= 0; } } } while (flt_a != 0.0 || flt_b != 0.0 || flt_c != 0.0); printf("n"); printf("n"); printf("Program terminated:n"); printf("n"); } What am I missing, cuz it complied perfectly?
 The meaning of life is curiosity; we were put on this planet to explore opportunities.
 PPGMD From United States of America, joined Sep 2001, 2453 posts, RR: 0 Reply 1, posted Tue Nov 5 2002 05:39:34 UTC (13 years 3 months 1 week 1 day 12 hours ago) and read 1410 times:

 At worst, you screw up and die.
 PPGMD From United States of America, joined Sep 2001, 2453 posts, RR: 0 Reply 2, posted Tue Nov 5 2002 05:41:11 UTC (13 years 3 months 1 week 1 day 12 hours ago) and read 1408 times:

 Also just a tip its bad programming mojo/style to declare all your varibles are global varibles.
 At worst, you screw up and die.
 Lehpron From United States of America, joined Jul 2001, 7028 posts, RR: 19 Reply 3, posted Tue Nov 5 2002 05:47:17 UTC (13 years 3 months 1 week 1 day 11 hours ago) and read 1406 times:

 Sorry, it was supposed to be: #include (stdio.h) #include (math.h) the carrots make the *.h files disappear. Our teacher couldn't care less about complex roots, we should just let everything equal -999.99. I have not got there yet.
 The meaning of life is curiosity; we were put on this planet to explore opportunities.
 PPGMD From United States of America, joined Sep 2001, 2453 posts, RR: 0 Reply 4, posted Tue Nov 5 2002 05:50:42 UTC (13 years 3 months 1 week 1 day 11 hours ago) and read 1404 times:

 Got any test cases that I could run though it.
 At worst, you screw up and die.
 PPGMD From United States of America, joined Sep 2001, 2453 posts, RR: 0 Reply 5, posted Tue Nov 5 2002 05:54:41 UTC (13 years 3 months 1 week 1 day 11 hours ago) and read 1399 times:

 First problem: while (flt_a != 0.0 || flt_b != 0.0 || flt_c != 0.0); should be: while (flt_a != 0.0 && flt_b != 0.0 && flt_c != 0.0); Need to use ands and not ors. Second problem you have no output until the program exits? That doesn't seem right.
 At worst, you screw up and die.
 PPGMD From United States of America, joined Sep 2001, 2453 posts, RR: 0 Reply 6, posted Tue Nov 5 2002 05:56:14 UTC (13 years 3 months 1 week 1 day 11 hours ago) and read 1398 times:

 third problem all you n's should be /n for new line.
 At worst, you screw up and die.
 Lehpron From United States of America, joined Jul 2001, 7028 posts, RR: 19 Reply 7, posted Tue Nov 5 2002 06:04:31 UTC (13 years 3 months 1 week 1 day 11 hours ago) and read 1395 times:

 Okay I changed the || into &&, now it loops through (like it supposed to) until put all coeff's as zero, then it freezes and doesn't terminate. What did you mean by "n's should be /n for new line"? Which lines are these in reference to?
 The meaning of life is curiosity; we were put on this planet to explore opportunities.
 Lehpron From United States of America, joined Jul 2001, 7028 posts, RR: 19 Reply 8, posted Tue Nov 5 2002 06:06:21 UTC (13 years 3 months 1 week 1 day 11 hours ago) and read 1393 times:

 In terms of out put, I'm taking baby steps to make sure this part works, if it does properly, i.e. it'll complie and run, then I'll just throw that stuff in last.
 The meaning of life is curiosity; we were put on this planet to explore opportunities.
 PPGMD From United States of America, joined Sep 2001, 2453 posts, RR: 0 Reply 9, posted Tue Nov 5 2002 06:11:38 UTC (13 years 3 months 1 week 1 day 11 hours ago) and read 1393 times:

 These three lines are a good example(there are more example that appear to need to be changed): printf("For formula reading Ax^2 + Bx + C = 0,n"); printf("n"); printf("Enter first coefficent, A:n"); Which has the output of: "For formula reading Ax^2 + Bx + C = 0,nnEnter first coefficent, A:n" They should be if I read your code right: printf("For formula reading Ax^2 + Bx + C = 0,/n"); printf("/n"); printf("Enter first coefficent, A:/n"); Which could have the output of: "For formula reading Ax^2 + Bx + C = 0, Enter first coefficent, A: " Sorry I can't help you much more, I do need to goto sleep I have a Digital Logic test in the morning. But I suggest that you print it out and go though it line by line on paper(away from the computer), you will see alot of mistakes that way. Thats the verification phase the Personal Software Process (PSP) which dominates my 4 years in Computer Science.
 At worst, you screw up and die.
 Lehpron From United States of America, joined Jul 2001, 7028 posts, RR: 19 Reply 10, posted Tue Nov 5 2002 06:23:59 UTC (13 years 3 months 1 week 1 day 11 hours ago) and read 1389 times:

 10Q 4 the help, PPGMD, good luck on ur test.
 The meaning of life is curiosity; we were put on this planet to explore opportunities.
 Top Of Page Change Forum... Civil Aviation Travel, Polls & Prefs Tech/Ops Aviation Hobby Aviation Photography Photography Feedback Trip Reports Military Av & Space Non-Aviation Site Related LIVE Chat Forum Index

This topic is archived and can not be replied to any more.

Printer friendly format

 Similar topics: More similar topics...
Is Someone Stealing My Internet? posted Thu May 25 2006 01:00:48 by BaylorAirBear
Someone Stole My Bike! posted Thu Mar 9 2006 18:53:37 by Airlinelover
Woodward: Libby Not My Source On Plame posted Wed Nov 16 2005 16:32:55 by Falcon84
So Someone Hijacked My EBay Account... posted Mon Jun 20 2005 04:06:22 by Trav110
"Help, Police...Someone Stole My Pot!" posted Wed Dec 8 2004 06:34:09 by MxCtrlr
Someone In Australia Wants To Access My Computer! posted Thu Apr 20 2006 01:21:11 by Senorcarnival
Someone Dented & Scratched My Car With Their Door! posted Mon Oct 31 2005 10:03:24 by Aer Lingus
I Just Caught Someone Trying To Burgle My House. posted Sat Apr 5 2003 21:02:12 by Toady
Someone Tried To Get Into My House! posted Thu Feb 14 2002 02:12:53 by EGGD
How Could I Do This To My Car!?!?!? posted Sat Dec 2 2006 18:46:27 by F.pier