Overclock.net banner

1 - 2 of 2 Posts

·
Registered
Joined
·
6 Posts
Discussion Starter · #1 ·
Hey everyone. i got stuck doing a very basic program. the purpose is to find the area of a triangle, and the problem is that the user is able to input two figures, but unless I insert control-d, the result doesn't appear. Here's the code, please help me fix it:

#include

int main(void)
{
double breadth, height, area;

printf("insert breadth, height\n");
scanf("%lf %lf\n", &breadth, &height);
area= 0.5*breadth*height;
printf("%lf\n", area);

return 0;
}
 

·
Registered
Joined
·
107 Posts
Remove the newline character from your scanf call... or better yet, don't use scanf and instead write a function specifically to capture the input you require(hint: strtod could prove helpful).
 
1 - 2 of 2 Posts
Top