Getting Duplicate Lines on printf

Thread Starter

beeson76

Joined Apr 19, 2010
211
Im working on functions and passing values between functions. Here is a short program I wrote that gives a square root of a number entered (actually the number entered is the square root), but I am not using the sqrt(); function provided in math.h.

Here is the output:

Enter a number: (I enter lets say 10)
Enter a number: (I enter 10 again)

Then it gives me the answer. Why does it want me to enter a number twice, with the second entry being the one it takes. I am using the Command line of Microsoft Visual Studio Express 2010 as my compiler.

Rich (BB code):
#include <stdio.h>

double square(void);

int main(void)
{
	square();   //goes to function square() to computer
	
	printf("Square root of number is %lf", square());

	return 0;
}


double square(void)
{
	double number;
	
	printf("Enter a number: \n");  
	scanf("%lf", &number);

	number = number * number;
	
	return number;
}
 
Top