Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes between Version 1 and Version 2 of MakingCalculations

Show
Ignore:
Author:
jcc7 (IP: 68.97.93.38)
Timestamp:
11/05/05 00:16:33 (14 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MakingCalculations

    v1 v2  
    1 = Declaring Variables = 
     1= Making Calculations = 
    22 
    33''Part of'' TutorialFundamentals 
    44 
    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''
     5This program demonstrates getting input from the console window, making a simple calculation, and returing the output
    66 
    77{{{ 
    88#!d 
     9/*  
     10    Purpose: Calculate the area of a circle 
     11    Author:  J C Calvarese 
     12    License: Public Domain  
     13*/ 
     14 
     15import std.c.stdio; /* for scanf */ 
     16import std.stdio;   /* for writef/writefln */ 
     17 
     18const double pi = 3.141592654; 
     19 
    920void main() 
    1021{ 
    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);     
    1533} 
    1634}}} 
     35 
     36When you run it, the console screen should look something like this (if you provide a radius of 5): 
     37{{{ 
     38Let's calculate the area of a circle. 
     39What is the radius? 5 
     40Area: 78.5398 
     41}}}