On Saturday, 20 April 2013 at 12:52:30 UTC, Carlos wrote:
Hi guys! I'm writing a little program in D from another version I did for my homework written in C. But it doesn't work very well. First it takes two reads for the first input from the user and second it only calculates tcsleep.

Here is the code:

import std.stdio;
import std.c.stdlib;
void main()
{
immutable sitc = 1.66;
immutable sleepc = 1.08;
float tcsleep, tcsit, tc;
int minsleep, minsit;
write("Input number of minutes sleep : \n");
readf("%d ", &minsleep);

write("Input number of minutes sitting : \n");
readf("%d ", &minsit);

write("Thanks!\n");
tcsleep = minsit*sitc;
tcsit = minsleep*sleepc;
tc = tcsleep+tcsit;
writeln("Your total calories is : ", tc);
exit (0);
}

First off, great on you for rewriting an old assignment in a new language. That's one of the better ways I've found to learn new languages (and I learn new languages all the time) because it allows you to focus on the new language and how you might use that language rather than solving the problem at hand.

Second, this probably should be in D.learn (if I don't say it, someone else will). http://forum.dlang.org/group/digitalmars.D.learn if you're using the web interface.

Third, "exit(0)" is redundant in D. It'll exit with code 0 as long as execution terminates normally (i.e., no exceptions thrown).

Finally, what "doesn't work very well"? Without more information, I don't think anyone will be able to help you.

Take care.

Reply via email to