Changes between Version 1 and Version 2 of MakingCalculations
 Timestamp:
 11/05/05 00:16:33 (14 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

MakingCalculations
v1 v2 1 = Declaring Variables =1 = Making Calculations = 2 2 3 3 ''Part of'' TutorialFundamentals 4 4 5 In order to store information within a D program, you must declare variables before they are used. The syntax is ''name_of_type'' ''identifier''.5 This program demonstrates getting input from the console window, making a simple calculation, and returing the output. 6 6 7 7 {{{ 8 8 #!d 9 /* 10 Purpose: Calculate the area of a circle 11 Author: J C Calvarese 12 License: Public Domain 13 */ 14 15 import std.c.stdio; /* for scanf */ 16 import std.stdio; /* for writef/writefln */ 17 18 const double pi = 3.141592654; 19 9 20 void main() 10 21 { 11 int myInteger; 12 double myDouble; 13 bit myBit; 14 char[] myString; 22 writefln("Let's calculate the area of a circle."); 23 24 writef("What is the radius? "); 25 26 double radius; 27 scanf("%lf", &radius); 28 29 double area; 30 area = pi * radius * radius; 31 32 writefln("Area: %s", area); 15 33 } 16 34 }}} 35 36 When you run it, the console screen should look something like this (if you provide a radius of 5): 37 {{{ 38 Let's calculate the area of a circle. 39 What is the radius? 5 40 Area: 78.5398 41 }}}