So I tried to put a program to calculate triangle height here it is :
#include <stdio.h>
void main()
{
float shorty_to_lefty=0.0f , lofty_to_tree=0.0f, lofty=0.0f , shorty=0.0f , arbre=0.0f;
printf("\nRentrer la distance entre le petit et le grand:" );
scanf("%0.2f", &shorty_to_lefty);
printf("\nRentrer la distance entre le grand et l'arbre:" );
scanf("%0.2f", &lofty_to_tree);
printf("\nRentrer la taille du petit" );
scanf("%0.2f", &shorty);
printf("\nRentrer la taille du grand:" );
scanf("%0.2f", &lofty);
arbre= lofty (shorty_to_lefty/lofty_to_tree)(lofty-shorty)/shorty_to_lefty;
printf("La taille de l'arbre est de %.2f m", arbre);
}
But the problem is when I launch it the scanf only input 1 value and not the rest ex: Rentrer la distance entre le petit et le grand:
2
Rentrer la distance entre le grand et l'arbre:
Rentrer la taille du petit
Rentrer la taille du grand:La taille de l'arbre est de -1.#J m
and in the last float arbre= lofty (shorty_to_lefty/lofty_to_tree)(lofty-shorty)/shorty_to_lefty
when i try to compile I get this error
Arbre.c: In function 'main':
Arbre.c:16:34: error: called object is not a function or function pointer
arbre= lofty (shorty_to_lefty/lofty_to_tree)(lofty-shorty)/shorty_to_lefty;
(there is an arrow under (shorty_to_lefty/lofty_to_tree)
)
CodePudding user response:
I found that for the input i need to put really a float for it to work ex:2.534
and not just a int , but still cant figure out for the last value & is there a way to include both float and int in a scanf
line?
CodePudding user response:
Problem number 1:
Replace %0.2f
with %f
. The scanf
format specifiers are similar to the ones of printf
but not identical.
Problem number 2:
...lofty_to_tree) (lofty - shorty) ...
^
an operator is misssing here, possibly *