111
Lisa via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Feb 21 04:35:31 PST 2016
On Saturday, 20 February 2016 at 12:59:58 UTC, Ivan Kazmenko
wrote:
> 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".
import std.stdio;
import std.math;
void main() {
writef("Enter side A: ");
double A;
readf("%s", &A);
writef("Enter side B: ");
double B;
readf("%s", &B);
writef("Enter side C: ");
double C;
readf("%s", &C);
writefln("Perimetr is", A + B + C, " centimetrs.");
return 0;
}
Is there smth wrong again?
More information about the Digitalmars-d-learn
mailing list