111

Ivan Kazmenko via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 20 04:59:58 PST 2016


On Saturday, 20 February 2016 at 04:15:50 UTC, Lisa wrote:
> 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

The line "int A, B, C;" should be "double A, B, C;" if you want 
to be able to operate non-integer lengths as well.

The lines like "readf("%lf", %A);" should be "readf(" %s", &A);". 
  Please read the reasoning again carefully in Ali's book: 
http://ddili.org/ders/d.en/input.html.  The " %s" can be " %f" 
but not " %lf" (that would be the correct string for C's printf 
but not for D's readf), and the leading space is important.

On the output line, you perhaps meant "writefln" instead of 
"writefl".  Again, "%lf" should be changed into "%f" or "%s".



More information about the Digitalmars-d-learn mailing list