Hi all,
I have a test in the morning and cant get my program to compile any suggestions would be great!
Code:
#include <stdio.h>
float absoluteValue (float x)
{
if (x < 0)
x = -x;
return (x);
}
//Function to compute the sqaure root of a number
float SquareRoot (float x)
{
float guess = 1.0;
float epsilon = .00001;
while ( absoluteValue((guess * guess) / x - 1.0) >= epsilon )
guess = ( x / guess + guess ) / 2.0;
return guess;
}
int main(void)
{
printf("SquareRoot (2.0) = %2.f\n", SqaureRoot (2.0));
printf("SquareRoot (144.0) = %2.f\n",SquareRoot (144.0));
printf("SquareRoot (17.5) = %2.f\n", SqaureRoot (17.5));
return 0;
}
//compiler error
prog8.5.c: In function ‘main’:
prog8.5.c:29: warning: format ‘%2.f’ expects type ‘double’, but argument 2 has type ‘int’
prog8.5.c:31: warning: format ‘%2.f’ expects type ‘double’, but argument 2 has type ‘int’
/tmp/ccL4vQGf.o: In function `main':
prog8.5.c:(.text+0x98): undefined reference to `SqaureRoot'
prog8.5.c:(.text+0xd5): undefined reference to `SqaureRoot'
collect2: ld returned 1 exit status