On Saturday, 20 February 2016 at 03:43:17 UTC, Ali Çehreli wrote:
On 02/19/2016 07:37 PM, Lisa wrote:
> import std.stdio;
> import std.math;
>
> int main()
> {
> double a, b, c, p;
>
> writef("Enter a: ");
> scanf("%d", &a);
scanf is not a safe function. It trusts the format string and
assumes that 'a' really is what the programmer told it. (For
example, although 'a' is not an 'int, %d means 'int' and scanf
treats it as such.)
The correct format identifier for double is %lf. You need to
replace all three of with %lf.
However, you are not writing idiomatic D code. I recommend
dropping C functions altogether an taking advantage of readf():
http://ddili.org/ders/d.en/input.html
Ali
module main;
import std.stdio;
import std.math;
int main() {
int A, B, C;
writef("A = ");
readf("%lf", %A);
writef("B = ");
readf("%lf", %B);
writef("C1= ");
readf("%lf", %C);
writefl("P = (%lf)", A + B + C);
return 0;
}
It whatever doesn't work