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

Get a number from the user (uses scanf)

Part of TutorialFundamentals

Description

Shows how you can ask the user for a number during runtime.

Example

import std.c.stdio; /* for scanf */
import std.stdio; /* for writef/writefln */

int main() {
  double n;

  writef("Pick a number: ");
  scanf("%lf", & n);

  writefln("You picked: %s", n);
  return 0;
}

Sample Batch File

@echo off
set pgm=ScanfExample
dmd %pgm%.d
%pgm%.exe
pause
erase %pgm%.obj
erase %pgm%.map

Tested Versions

Tested with Digital Mars D Compiler v1.0 on Windows 2000.