Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debugging help...

Status
Not open for further replies.

j0hnb

IS-IT--Management
Aug 31, 2004
11
US
here is my program and at the end I included the errors that my compiler showed.. please help me fix them. Thanks, john

-----------------------------------------------------

#include <stdio.h>

int main(void)
{
int balance, interest, min_payment_one, min_payment_two, balance_two, years, interest_multiplier, interest_addition;
float months_one, months_two, months_reduced;

/*Input for balance, interest and min_payment printing of lines 1-6*/

printf(&quot;Debt Analysis Program:\n&quot;);
printf(&quot;----------------------\n\n&quot;);
printf(&quot;Enter credit card's current balance: &quot;);
scanf(&quot;%d&quot;, &balance);
printf(&quot;\nEnter annual intrest rate (as decimal): &quot;);
scanf(&quot;%d&quot;, &interest);
printf(&quot;\nEnter minimum payment: &quot;);
scanf(&quot;%d&quot;, &min_payment_one);

/*Calculations for months_one*/

months_one = balance / min_payment_one;
years = months_one / 12;
years = ceil(years);
interest_multiplier = years * interest;
interest_addition = balance * interest_multiplier;
balance_two = interest_addition + balance;
months_one = balance_two / min_payment_one;
months_one = ceil(months_one);

/*printing of lines 7-12 and scanning of min_payment_two*/

printf(&quot;\n\nIt will take %f months to payoff this card with this minimum payment.\n\n&quot;, months_one);
printf(&quot;Try Increasing your payment by at lease $10...\n\n&quot;);
printf(&quot;New minimum payment: &quot;);
scanf(&quot;%d, &min_payment_two);

/*calculations for months_two and months_reduced*/

months_two = balance / min_payment_two;
years = months_two / 12;
years = ceil(years);
interest_multiplier = years * interest;
interest_addition = balance * interest_multiplier;
balance_two = interest_addition + balance;
months_two = balance_two / min_payment_two;
months_two = ceil(months_one);

months_reduced = months_one - months_two;

/*printing of lines 13-17*/

printf(&quot;\nNow it will take %f months to payoff this credit card.\n\n&quot;, months_two);
printf(&quot;You would reduce your load period by %f months with the new minimum payment.\n\n&quot;, months_reduced);
return 0;
}


--------------------------------------------------------


assign2.c:47:13: warning: multi-line string literals are deprecated
assign2.c: In function `main':
assign2.c:64: stray '\' in program
assign2.c:64: parse error before &quot;nNow&quot;
assign2.c:64: stray '\' in program
assign2.c:64: stray '\' in program
assign2.c:64:72: warning: multi-line string literals are deprecated
assign2.c:65: stray '\' in program
assign2.c:65: stray '\' in program
assign2.c:65:92: warning: multi-line string literals are deprecated
assign2.c:65:92: missing terminating &quot; character
assign2.c:47:13: possible start of unterminated string literal
assign2.c:67:5: warning: no newline at end of file

 
Missing quote in

scanf(&quot;%d, &min_payment_two);

near

/*printing of lines 7-12 and scanning of in_payment_two*/

Also, if your string literals are getting too long, you could split them over several lines

eg

&quot;the &quot;
&quot;quick brown &quot;
&quot;fox&quot;

is the same as

&quot;the quick brown fox&quot;
 
Looks like a simple typo - in the section of code reproduced below

printf(&quot;New minimum payment: &quot;);
scanf(&quot;%d, &min_payment_two);

you have missed the trailing &quot; sign after the %d in the scanf call, it should read

printf(&quot;New minimum payment: &quot;);
scanf(&quot;%d&quot;, &min_payment_two);

Cheers - Gavin
 
Alright I fixed all of those errors and Now I am stuck with one error left:
/var/tmp/ccuhELub.o(.text+0x264): undefined reference to `ceil'

so now what?

------------------------------------------

#include <stdio.h>

int main(void)
{
float months_two, years, months_one, months_reduced, balance, interest, min_payment_one, min_payment_two, balance_two, interest_multiplier, interest_addition;

/*Input for balance, interest and min_payment printing of lines 1-6*/

printf(&quot;Debt Analysis Program:\n&quot;);
printf(&quot;----------------------\n\n&quot;);
printf(&quot;Enter credit card's current balance: &quot;);
scanf(&quot;%f&quot;, &balance);
printf(&quot;\nEnter annual intrest rate (as decimal): &quot;);
scanf(&quot;%f&quot;, &interest);
printf(&quot;\nEnter minimum payment: &quot;);
scanf(&quot;%f&quot;, &min_payment_one);

/*Calculations for months_one*/

months_one = balance / min_payment_one;
years = months_one / 12;
years = ceil(years);
interest_multiplier = years * interest;
interest_addition = balance * interest_multiplier;
balance_two = interest_addition + balance;
months_one = balance_two / min_payment_one;
months_one = ceil(months_one);

/*printing of lines 7-12 and */
/*scanning of min_payment_two*/

printf(&quot;\n\nIt will take %f months to payoff this card with this minimum payment.\n\n&quot;, months_one);
printf(&quot;Try Increasing your payment by at lease $10...\n\n&quot;);
printf(&quot;New minimum payment: &quot;);
scanf(&quot;%d&quot;, &min_payment_two);

/*calculations for months_two and months_reduced*/

months_two = balance / min_payment_two;
years = months_two / 12;
years = ceil(years);
interest_multiplier = years * interest;
interest_addition = balance * interest_multiplier;
balance_two = interest_addition + balance;
months_two = balance_two / min_payment_two;
months_two = ceil(months_one);

months_reduced = months_one - months_two;

/*printing of lines 13-17*/

printf(&quot;\nNow it will take %f months to payoff this credit card.\n\n&quot;, months_two);
printf(&quot;You would reduce your load period by %f months with the new minimum payment.\n\n&quot;, months_reduced);
return 0;
}

----------------------------------------------------

/var/tmp/ccuhELub.o: In function `main':
/var/tmp/ccuhELub.o(.text+0xd0): undefined reference to `ceil'
/var/tmp/ccuhELub.o(.text+0x140): undefined reference to `ceil'
/var/tmp/ccuhELub.o(.text+0x1f4): undefined reference to `ceil'
/var/tmp/ccuhELub.o(.text+0x264): undefined reference to `ceil'
collect2: ld returned 1 exit status
 
Hi:

Typically, with an error like this, you've forgotten a header file. It's probably compiler dependent, but I think the header file you're looking for is math.h.

Regards,

Ed
 
I think it's more likely that you haven't linked the maths library in. If it was just the omission of the header the compile would most likely work but complain about function declarations.

The fact that ld is complaining about errors in the .o module (ie the object) points to the maths libraries not being included in the link editor step.

How to fix this depends on the compiler being used.
 
From your output it looks to me like you're using gcc, the command line you need is as follows :

gcc -o appname appname.c -lm

the -lm links in the match libraries.

Hope this helps - Gavin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top