User input/Text: Difference between revisions

→‎{{header|BabyCobol}}: conform to the task definition
No edit summary
(→‎{{header|BabyCobol}}: conform to the task definition)
 
(25 intermediate revisions by 18 users not shown)
Line 12:
 
=={{header|11l}}==
<langsyntaxhighlight lang="11l">V string = input(‘Input a string: ’)
V number = Float(input(‘Input a number: ’))</langsyntaxhighlight>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B/4 version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
<lang AArch64 Assembly>
//Consts
.equ BUFFERSIZE, 100
Line 86:
svc 0 // trigger end of program
 
</syntaxhighlight>
</lang>
 
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "H6:REALMATH.ACT"
 
PROC Main()
Line 113:
Print("Text: ") PrintE(sUser)
Print("Number: ") PrintRE(rUser)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/User_input_Text.png Screenshot from Atari 8-bit computer]
Line 128:
=={{header|Ada}}==
{{works with|GCC|4.1.2}}
<langsyntaxhighlight lang="ada">function Get_String return String is
Line : String (1 .. 1_000);
Last : Natural;
Line 142:
-- may raise exception Constraint_Error if value entered is not a well-formed integer
end Get_Integer;
</syntaxhighlight>
</lang>
 
The functions above may be called as shown below
<langsyntaxhighlight lang="ada">My_String : String := Get_String;
My_Integer : Integer := Get_Integer;</langsyntaxhighlight>
 
Another:
<langsyntaxhighlight lang="ada">with Ada.Text_IO, Ada.Integer_Text_IO;
 
procedure User_Input is
Line 164:
Ada.Text_IO.Put_Line (Integer'Image(I));
end User_Input;
</syntaxhighlight>
</lang>
 
Unbounded IO:
<langsyntaxhighlight lang="ada">with
Ada.Text_IO,
Ada.Integer_Text_IO,
Line 185:
Ada.Text_IO.Put_Line(Integer'Image(I));
end User_Input2;
</syntaxhighlight>
</lang>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">print("Enter a string: ");
STRING s := read string;
print("Enter a number: ");
INT i := read int;
~</langsyntaxhighlight>
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
string(80) s;
integer n;
Line 202:
write( "Enter an integer> " );
read( n )
end.</langsyntaxhighlight>
 
=={{header|Amazing Hopper}}==
Version: hopper-FLOW!
<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#include <flow.h>
 
Line 219:
LOCATE(5,2), PRNL( cadena, "\n ",número )
END
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 230:
 
=={{header|APL}}==
<langsyntaxhighlight APLlang="apl">str←⍞
int←⎕</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
<lang ARM Assembly>
 
/* ARM assembly Raspberry PI */
Line 387:
szMessErrDep: .asciz "Too large: overflow 32 bits.\n"
 
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">str: input "Enter a string: "
num: to :integer input "Enter an integer: "
 
print ["Got:" str "," num]</langsyntaxhighlight>
 
{{out}}
Line 404:
=={{header|AutoHotkey}}==
===Windows console===
<langsyntaxhighlight AutoHotkeylang="autohotkey">DllCall("AllocConsole")
FileAppend, please type something`n, CONOUT$
FileReadLine, line, CONIN$, 1
Line 410:
FileAppend, please type '75000'`n, CONOUT$
FileReadLine, line, CONIN$, 1
msgbox % line</langsyntaxhighlight>
 
===Input Command===
this one takes input regardless of which application has focus.
<langsyntaxhighlight AutoHotkeylang="autohotkey">TrayTip, Input:, Type a string:
Input(String)
TrayTip, Input:, Type an int:
Line 436:
TrayTip, Input:, %Output%
}
}</langsyntaxhighlight>
 
=={{header|AWK}}==
This demo shows a same-line prompt, and that the integer i becomes 0 if the line did not parse as an integer.
<langsyntaxhighlight lang="awk">~/src/opt/run $ awk 'BEGIN{printf "enter a string: "}{s=$0;i=$0+0;print "ok,"s"/"i}'
enter a string: hello world
ok,hello world/0
75000
ok,75000/75000</langsyntaxhighlight>
 
=={{header|Axe}}==
Line 453:
Also, in the string entry, the data is a string of tokens, not a string of characters. Thankfully, the most common ASCII symbols (A-Z, 0-9, and some symbols) have the same values as their token counterparts. This means that this example will work for those symbols, but other tokens (especially multi-byte tokens) will cause problems. See [http://tibasicdev.wikidot.com/one-byte-tokens this table] of tokens and their codes for reference.
 
<langsyntaxhighlight lang="axe">Disp "String:"
input→A
length(A)→L
Line 487:
If C≠7500
Disp "That isn't 7500"
End</langsyntaxhighlight>
 
=={{header|BabyCobol}}==
<syntaxhighlight lang="cobol">
* NB: whitespace insignificance and case insensitivity
* are used in the field name.
IDENTIFICATION DIVISION.
PROGRAM-ID. USER INPUT.
DATA DIVISION.
01 HUNDRED CHAR STRING PICTURE IS X(100).
01 FIVE DIGIT NUMBER PICTURE IS 9(5).
PROCEDURE DIVISION.
DISPLAY "Enter a string of appropriate length: " WITH NO ADVANCING
ACCEPT HundredChar String.
DISPLAY "Enter a number (preferably 75000): " WITH NO ADVANCING
ACCEPT FiveDigit Number.
</syntaxhighlight>
 
=={{header|BASIC}}==
Line 496 ⟶ 512:
This isn't a hard-and-fast rule -- for example, [[Chipmunk Basic]] ''never'' appends a question mark.
 
<langsyntaxhighlight lang="qbasic">INPUT "Enter a string"; s$
INPUT "Enter a number: ", i%</langsyntaxhighlight>
 
Output ([[QBasic]]):
Line 503 ⟶ 519:
Enter a number: 1
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight lang="basic">10 INPUT "ENTER A STRING: "; S$
20 INPUT "ENTER A NUMBER: "; I : I = INT(I)</langsyntaxhighlight>
 
==={{header|Commodore BASIC}}===
Line 511 ⟶ 527:
Also, when a numeric variable is provided for input, the computer will make repeated attempts to obtain valid input from the user until the input can be clearly interpreted as a numeric value.
 
<langsyntaxhighlight lang="gwbasic">
10 input "what is a word i should remember";a$
20 print "thank you."
Line 520 ⟶ 536:
70 print nn
80 end
</syntaxhighlight>
</lang>
 
'''Output'''
Line 543 ⟶ 559:
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 INPUT PROMPT "Enter a number: ":NUM
110 INPUT PROMPT "Enter a string: ":ST$</langsyntaxhighlight>
 
==={{header|QB64}}===
The use of a Long int (l&) is required as the Int variable type is only 2 bytes and even if _UNSIGNED can only hold values up to 65535. If no value is entered for either input value, it will continue to hold whatever value it did previously.
<langsyntaxhighlight QB64lang="qb64">Input "Enter text and a number", s$, l&
Print s$
Print l&
</syntaxhighlight>
</lang>
 
==={{header|BASIC256}}===
<langsyntaxhighlight lang="freebasic">input string "Please enter a string: ", s
do
input "Please enter 75000 : ", i
until i = 75000
print
print s, i</langsyntaxhighlight>
 
==={{header|Run BASIC}}===
<langsyntaxhighlight lang="runbasic">input "Please enter a string: "; s$
while i <> 75000
input "Please enter 75000 : "; i
wend
print
print s$; chr$(9); i</langsyntaxhighlight>
 
==={{header|True BASIC}}===
{{works with|QBasic}}
<langsyntaxhighlight lang="qbasic">PRINT "Please enter a string";
INPUT s$
DO
Line 579 ⟶ 595:
PRINT
PRINT s$, i
END</langsyntaxhighlight>
 
==={{header|Yabasic}}===
<langsyntaxhighlight lang="freebasic">input "Please enter a string: " s$
repeat
input "Please enter 75000 : " i
until i = 75000
print
print s$, chr$(9), i</langsyntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
<langsyntaxhighlight lang="basic">10 PRINT "ENTER A STRING"
20 INPUT S$
30 PRINT "YOU ENTERED: ";S$
Line 597 ⟶ 613:
60 IF N=75000 THEN STOP
70 PRINT "NO, ";
80 GOTO 40</langsyntaxhighlight>
 
=={{header|Batch File}}==
 
<langsyntaxhighlight lang="dos">@echo off
set /p var=
echo %var% 75000</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic"> INPUT LINE "Enter a string: " string$
INPUT "Enter a number: " number
PRINT "String = """ string$ """"
PRINT "Number = " ; number</langsyntaxhighlight>
 
=={{header|Befunge}}==
This prompts for a string and pushes it to the stack a character at a time ('''~''') until end of input (-1).
<langsyntaxhighlight lang="befunge"><>:v:"Enter a string: "
^,_ >~:1+v
^ _@</langsyntaxhighlight>
 
Numeric input is easier, using the '''&''' command.
<langsyntaxhighlight lang="befunge"><>:v:"Enter a number: "
^,_ & @</langsyntaxhighlight>
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat">( doit
= out'"Enter a string"
& get':?mystring
Line 633 ⟶ 649:
)
& out$(mystring is !mystring \nmynumber is !mynumber \n)
);</langsyntaxhighlight>
<pre>{?} !doit
Enter a string
Line 646 ⟶ 662:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
 
Line 667 ⟶ 683:
 
return EXIT_SUCCESS;
}</langsyntaxhighlight>
 
==={{libheader|Gadget}}===
<syntaxhighlight lang="c">
#include <gadget/gadget.h>
 
LIB_GADGET_START
 
Main
Cls;
String text;
int number=0;
At 5,5; Print "Enter text : ";
Atrow 7; Print "Enter ‘75000’: ";
Atcol 20;
Atrow 5; Fn_let(text, Input ( text, 30 ) );
Free secure text;
Atrow 7; Stack{
while (number!=75000 )
/*into stack, Input() not need var*/
number = Str2int( Input ( NULL, 6 ) );
}Stack_off;
 
Prnl;
End
</syntaxhighlight>
{{out}}
<pre>
$ ./tests/input_cons
 
 
 
 
Enter text : Juanita la mañosa
 
Enter ‘75000’: 75000
$
</pre>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
namespace C_Sharp_Console {
Line 686 ⟶ 743:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{works with|g++}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <string>
using namespace std;
Line 705 ⟶ 762:
cin >> string_input;
return 0;
}</langsyntaxhighlight>
 
Note: The program as written above only reads the string up to the first whitespace character. To get a complete line into the string, replace
<syntaxhighlight lang ="cpp"> cin >> string_input;</langsyntaxhighlight>
with
<syntaxhighlight lang ="cpp"> getline(cin, string_input);</langsyntaxhighlight>
 
Note: if a numeric input operation fails, the value is not stored for that operation, plus the ''fail bit'' is set, which causes all future stream operations to be ignored (e.g. if a non-integer is entered for the first input above, then nothing will be stored in either the integer and the string). A more complete program would test for an error in the input (with <code>if (!cin) // handle error</code>) after the first input, and then clear the error (with <code>cin.clear()</code>) if we want to get further input.
Line 717 ⟶ 774:
 
=={{header|Ceylon}}==
<langsyntaxhighlight lang="ceylon">shared void run() {
print("enter any text here");
value text = process.readLine();
Line 728 ⟶ 785:
print("That was not a number per se.");
}
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="lisp">(import '(java.util Scanner))
(def scan (Scanner. *in*))
(def s (.nextLine scan))
(def n (.nextInt scan))</langsyntaxhighlight>
 
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. Get-Input.
 
Line 754 ⟶ 811:
 
GOBACK
.</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(format t "Enter some text: ")
(let ((s (read-line)))
(format t "You entered ~s~%" s))
Line 765 ⟶ 822:
(if (numberp n)
(format t "You entered ~d.~%" n)
(format t "That was not a number.")))</langsyntaxhighlight>
 
=={{header|Crystal}}==
 
<langsyntaxhighlight lang="ruby">puts "You entered: #{gets}"
 
begin
Line 775 ⟶ 832:
rescue ex
puts ex
end</langsyntaxhighlight>
 
Example with valid input:
Line 794 ⟶ 851:
 
=={{header|D}}==
<langsyntaxhighlight Dlang="d">import std.stdio;
void main() {
Line 806 ⟶ 863:
writeln("Read in '", number, "' and '", str, "'");
}</langsyntaxhighlight>
 
=={{header|Dart}}==
<langsyntaxhighlight lang="javascript">import 'dart:io' show stdout, stdin;
 
main() {
Line 836 ⟶ 893:
}
 
</syntaxhighlight>
</lang>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program UserInputText;
 
{$APPTYPE CONSOLE}
Line 860 ⟶ 917:
Writeln('Invalid entry: ' + s);
until lIntegerValue = 75000;
end.</langsyntaxhighlight>
 
=={{header|Déjà Vu}}==
<langsyntaxhighlight lang="dejavu">input s:
!print\ s
!decode!utf-8 !read-line!stdin
Line 873 ⟶ 930:
/= 75000
catch value-error:
true</langsyntaxhighlight>
 
=={{header|EasyLang}}==
 
<syntaxhighlight lang="text">write "Enter a string: "
a$ = input
print ""
Line 886 ⟶ 943:
until h = 75000
.
print a$ & " " & h</langsyntaxhighlight>
 
=={{header|Elena}}==
ELENA 46.x :
<langsyntaxhighlight lang="elena">import extensions;
public program()
{
var num := new Integer();
console.write:("Enter an integer: ").loadLineTo:(num);
var word := console.write:("Enter a String: ").readLine()
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">
<lang Elixir>
a = IO.gets("Enter a string: ") |> String.strip
b = IO.gets("Enter an integer: ") |> String.strip |> String.to_integer
Line 908 ⟶ 965:
IO.puts "Integer = #{b}"
IO.puts "Float = #{f}"
</syntaxhighlight>
</lang>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">{ok, [String]} = io:fread("Enter a string: ","~s").
{ok, [Number]} = io:fread("Enter a number: ","~d").</langsyntaxhighlight>
 
Alternatively, you could use io:get_line to get a string:
<langsyntaxhighlight lang="erlang"> String = io:get_line("Enter a string: ").</langsyntaxhighlight>
 
=={{header|Euphoria}}==
<langsyntaxhighlight Euphorialang="euphoria">include get.e
 
sequence s
Line 926 ⟶ 983:
puts(1, s & '\n')
n = prompt_number("Enter a number:",{})
printf(1, "%d", n)</langsyntaxhighlight>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System
 
let ask_for_input s =
Line 939 ⟶ 996:
ask_for_input "Input a string" |> ignore
ask_for_input "Enter the number 75000" |> ignore
0</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">"Enter a string: " write
readln
"Enter a number: " write
readln string>number</langsyntaxhighlight>
 
=={{header|Falcon}}==
<langsyntaxhighlight lang="falcon">printl("Enter a string:")
str = input()
printl("Enter a number:")
n = int(input())</langsyntaxhighlight>
 
=={{header|FALSE}}==
FALSE has neither a string type nor numeric input. Shown instead are routines to parse and echo a word and to parse and interpret a number using the character input command (^).
<langsyntaxhighlight lang="false">[[^$' =~][,]#,]w:
[0[^'0-$$9>0@>|~][\10*+]#%]d:
w;! d;!.</langsyntaxhighlight>
 
=={{header|Fantom}}==
Line 963 ⟶ 1,020:
The 'toInt' method on an input string will throw an exception if the input is not a number.
 
<langsyntaxhighlight lang="fantom">
class Main
{
Line 982 ⟶ 1,039:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
===Input a string===
 
<langsyntaxhighlight lang="forth">: INPUT$ ( n -- addr n )
PAD SWAP ACCEPT
PAD SWAP ;</langsyntaxhighlight>
 
===Input a number===
The only ANS standard number interpretation word is >NUMBER ( ud str len -- ud str len ), which is meant to be the base factor for more convenient (but non-standard) parsing words.
<langsyntaxhighlight lang="forth">: INPUT# ( -- u true | false )
0. 16 INPUT$ DUP >R
>NUMBER NIP NIP
R> <> DUP 0= IF NIP THEN ;</langsyntaxhighlight>
 
{{works with|GNU Forth}}
<langsyntaxhighlight lang="forth">: INPUT# ( -- n true | d 1 | false )
16 INPUT$ SNUMBER? ;</langsyntaxhighlight>
 
{{works with|Win32Forth}}
<langsyntaxhighlight lang="forth">: INPUT# ( -- n true | false )
16 INPUT$ NUMBER? NIP
DUP 0= IF NIP THEN ;</langsyntaxhighlight>
 
Note that NUMBER? always leaves a double result on the stack.
Line 1,011 ⟶ 1,068:
 
{{works with|4tH}}
<langsyntaxhighlight lang="forth">: input#
begin
refill drop bl parse-word ( a n)
Line 1,018 ⟶ 1,075:
drop ( --)
repeat ( n)
;</langsyntaxhighlight>
 
Here is an example that puts it all together:
 
<langsyntaxhighlight lang="forth">: TEST
." Enter your name: " 80 INPUT$ CR
." Hello there, " TYPE CR
." Enter a number: " INPUT# CR
IF ." Your number is " .
ELSE ." That's not a number!" THEN CR ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran">character(20) :: s
integer :: i
 
Line 1,037 ⟶ 1,094:
read*, s
print*, "Enter the integer 75000"
read*, i</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Dim s As String
Line 1,050 ⟶ 1,107:
Print
Print s, i
Sleep</langsyntaxhighlight>
Sample input/output
{{out}}
Line 1,062 ⟶ 1,119:
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">
s = input["Enter a string: "]
i = parseInt[input["Enter an integer: "]]
</syntaxhighlight>
</lang>
 
=={{header|GDScript}}==
{{works with|Godot|4.0}}
 
Run with <code>godot --headless --script <file></code>
 
<syntaxhighlight lang="gdscript">
extends MainLoop
 
func _process(_delta: float) -> bool:
printraw("Input a string: ")
var read_line := OS.read_string_from_stdin() # Mote that this retains the newline.
 
printraw("Input an integer: ")
var read_integer := int(OS.read_string_from_stdin())
 
print("read_line = %s" % read_line.trim_suffix("\n"))
print("read_integer = %d" % read_integer)
 
return true # Exit instead of looping
</syntaxhighlight>
 
=={{header|Go}}==
Go has C-like Scan and Scanf functions for quick and dirty input:
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,081 ⟶ 1,159:
fmt.Println("wrong")
}
}</langsyntaxhighlight>
Code below allows much more control over interaction and error checking.
<syntaxhighlight lang="go">
<lang go>
package main
 
Line 1,122 ⟶ 1,200:
fmt.Println("Good")
}
</syntaxhighlight>
</lang>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">word = System.in.readLine()
num = System.in.readLine().toInteger()</langsyntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import System.IO (hFlush, stdout)
main = do
putStr "Enter a string: "
Line 1,137 ⟶ 1,215:
hFlush stdout
num <- readLn :: IO Int
putStrLn $ str ++ (show num)</langsyntaxhighlight>
Note: <tt>:: IO Int</tt> is only there to disambiguate what type we wanted from <tt>read</tt>. If <tt>num</tt> were used in a numerical context, its type would have been inferred by the interpreter/compiler.
Note also: Haskell doesn't automatically flush stdout when doing input, so explicit flushes are necessary.
 
=={{header|hexiscript}}==
<langsyntaxhighlight lang="hexiscript">print "Enter a string: "
let s scan str
print "Enter a number: "
let n scan int</langsyntaxhighlight>
 
=={{header|HolyC}}==
<langsyntaxhighlight lang="holyc">U8 *s;
s = GetStr("Enter a string: ");
 
Line 1,157 ⟶ 1,235:
 
Print("Your string: %s\n", s);
Print("75000: %d\n", Str2I64(n));</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 1,163 ⟶ 1,241:
The following works in both Icon and Unicon:
 
<langsyntaxhighlight lang="icon">
procedure main ()
writes ("Enter something: ")
Line 1,174 ⟶ 1,252:
else write ("you must enter a number")
end
</syntaxhighlight>
</lang>
 
=={{header|Io}}==
<langsyntaxhighlight lang="io">string := File clone standardInput readLine("Enter a string: ")
integer := File clone standardInput readLine("Enter 75000: ") asNumber</langsyntaxhighlight>
 
=={{header|J}}==
'''Solution'''
<langsyntaxhighlight lang="j"> require 'misc' NB. load system script
prompt 'Enter string: '
0".prompt 'Enter an integer: '</langsyntaxhighlight>
 
Note that <code>require'misc'</code> is old - efforts to optimize by loading misc utilities in a fine grained fashion mean that currently (J 805) that should be <code>require'general/misc/prompt'</code> and the older form fails with an error to call attention to this issue.
 
'''Example Usage'''
<langsyntaxhighlight lang="j"> prompt 'Enter string: ' NB. output string to session
Enter string: Hello World
Hello World
Line 1,203 ⟶ 1,281:
│Hello Rosetta Code│75000│
└──────────────────┴─────┘
</syntaxhighlight>
</lang>
 
=={{header|Java}}==
 
<langsyntaxhighlight lang="java">
import java.util.Scanner;
 
Line 1,218 ⟶ 1,296:
int i = Integer.parseInt(s.next());
}
}</langsyntaxhighlight>
 
or
 
{{works with|Java|1.5/5.0+}}
<langsyntaxhighlight lang="java">import java.util.Scanner;
 
public class GetInput {
Line 1,231 ⟶ 1,309:
int number = stdin.nextInt();
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
{{works with|JScript}} and only with <code>cscript.exe</code>
<langsyntaxhighlight lang="javascript">WScript.Echo("Enter a string");
var str = WScript.StdIn.ReadLine();
 
Line 1,242 ⟶ 1,320:
WScript.Echo("Enter the integer 75000");
val = parseInt( WScript.StdIn.ReadLine() );
}</langsyntaxhighlight>
 
{{works with|SpiderMonkey}}
<langsyntaxhighlight lang="javascript">print("Enter a string");
var str = readline();
 
Line 1,252 ⟶ 1,330:
print("Enter the integer 75000");
val = parseInt( readline() );
}</langsyntaxhighlight>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">
<lang Joy>
"Enter a string: " putchars
stdin fgets
"Enter a number: " putchars
stdin fgets 10 strtol.
</syntaxhighlight>
</lang>
 
=={{header|jq}}==
Line 1,272 ⟶ 1,350:
encountered, then the following program could be used on the assumption that
the inputs are all valid JSON.
<langsyntaxhighlight lang="jq">def read(int):
null | until( . == int; "Expecting \(int)" | stderr | input);
Line 1,279 ⟶ 1,357:
 
(read_string | "I see the string: \(.)"),
(read(75000) | "I see the expected integer: \(.)")</langsyntaxhighlight>
{{out}}
The following is a transcript showing the prompts (on stderr), responses (on stdin) and output (on stdout):
<langsyntaxhighlight lang="sh">$ jq -n -r -f User_input.jq
"Please enter a string"
1
Line 1,294 ⟶ 1,372:
"Expecting 75000"
75000
I see the expected integer: 75000</langsyntaxhighlight>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
<syntaxhighlight lang="julia">
<lang Julia>
print("String? ")
y = readline()
Line 1,310 ⟶ 1,388:
println("Sorry, but \"", y, "\" does not compute as an integer.")
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,329 ⟶ 1,407:
 
=={{header|Kite}}==
<syntaxhighlight lang="kite">
<lang Kite>
System.file.stdout|write("Enter a String ");
string = System.file.stdin|readline();
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1
 
fun main(args: Array<String>) {
Line 1,345 ⟶ 1,423:
val number = readLine()!!.toInt()
} while (number != 75000)
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
{input
{@ type="text"
placeholder="Please enter a string and dblclick"
ondblclick="alert( 'You wrote « ' +
this.value +
' » and it is ' +
((isNaN(this.value)) ? 'not' : '') +
' a number.' )"
}}
 
Please enter a string and dblclick
 
Input: Hello World
Output: You wrote « Hello World » and it is not a number.
 
Input: 123
Output: You wrote « 123 » and it is a number.
 
</syntaxhighlight>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">#!/usr/bin/lasso9
 
define read_input(prompt::string) => {
Line 1,378 ⟶ 1,478:
 
// deliver the result
stdoutnl(#string + ' (' + #string -> type + ') | ' + #number + ' (' + #number -> type + ')')</langsyntaxhighlight>
 
Output:
Line 1,385 ⟶ 1,485:
Hello (string) | 1234 (integer)
</pre>
 
=={{header|LDPL}}==
<syntaxhighlight lang="ldpl">data:
myText is text
myNumber is number
 
procedure:
display "Enter some text: "
accept myText
display "Enter a number: "
accept myNumber
</syntaxhighlight>
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb">Input "Enter a string. ";string$
Input "Enter the value 75000.";num</langsyntaxhighlight>
 
=={{header|LIL}}==
<langsyntaxhighlight lang="tcl"># User input/text, in LIL
write "Enter a string: "
set text [readline]
Line 1,402 ⟶ 1,514:
 
print $text
print $num</langsyntaxhighlight>
 
=={{header|Logo}}==
Logo literals may be read from a line of input from stdin as either a list or a single word.
<langsyntaxhighlight lang="logo">make "input readlist ; in: string 75000
show map "number? :input ; [false true]
 
Line 1,412 ⟶ 1,524:
show :input + 123 ; 75123
make "input readword ; in: string 75000
show :input ; string 75000</langsyntaxhighlight>
 
=={{header|Logtalk}}==
Using an atom representation for strings and type-check failure-driven loops:
<langsyntaxhighlight lang="logtalk">
:- object(user_input).
 
Line 1,433 ⟶ 1,545:
 
:- end_object.
</syntaxhighlight>
</lang>
Output:
<langsyntaxhighlight lang="text">
| ?- user_input::test.
Enter an integer: 75000.
Enter an atom: 'Hello world!'.
yes
</syntaxhighlight>
</lang>
 
=={{header|LOLCODE}}==
<langsyntaxhighlight LOLCODElang="lolcode">HAI 1.4
I HAS A string
GIMMEH string
Line 1,451 ⟶ 1,563:
MAEK number A NUMBR
KTHXBYE
</syntaxhighlight>
</lang>
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">print('Enter a string: ')
s = io.stdin:read()
print('Enter a number: ')
i = tonumber(io.stdin:read())
</syntaxhighlight>
</lang>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Keyboard "75000"+chr$(13)
Line 1,471 ⟶ 1,583:
}
CheckIt
</syntaxhighlight>
</lang>
 
=={{header|MACRO-10}}==
<syntaxhighlight lang="macro-10">
TITLE User Input
 
COMMENT !
User Input ** PDP-10 assembly language (kjx, 2022)
Assembler: MACRO-10 Operating system: TOPS-20
 
This program reads a string (maximum of 80 characters) and
a decimal number. The number is checked to be 75000. Invalid
input (like entering characters instead of a decimal number)
is detected, and an error message is printed in that case.
!
 
SEARCH MONSYM,MACSYM
.REQUIRE SYS:MACREL
 
STDAC. ;Set standard register names.
 
STRING: BLOCK 20 ;20 octal words = 80 characters.
NUMBER: BLOCK 1 ;1 word for number.
 
;;
;; Execution starts here:
;;
 
GO:: RESET% ;Initialize process.
 
;; Print prompt:
 
HRROI T1,[ASCIZ /Please type a string, 80 chars max.: /]
PSOUT%
;; Read string from terminal:
 
HRROI T1,STRING ;Pointer to string-buffer.
MOVEI T2,^D80 ;80 characters max.
SETZ T3 ;No special ctrl-r prompt.
RDTTY% ;Read from terminal.
ERJMP ERROR ; On error, go to ERROR.
 
;; Print second prompt:
 
NUMI: HRROI T1,[ASCIZ /Please type the decimal number 75000: /]
PSOUT%
;; Input number from terminal:
MOVEI T1,.PRIIN ;Read from terminal.
MOVEI T3,^D10 ;Decimal input.
NIN% ;Input number.
ERJMP ERROR ; On error, go to ERROR.
;; Make sure number is actually 75000.
CAIE T2,^D75000 ;Compare number...
JRST [ HRROI T1,[ASCIZ /Number is not 75000! /]
PSOUT% ; ...complain and
JRST NUMI ] ; try again.
MOVEM T2,NUMBER ;Store number if correct.
 
;; Now print out string and number:
 
HRROI T1,STRING ;String ptr into T1.
PSOUT% ;Print string.
 
MOVEI T1,.PRIOU ;Print on standard output.
MOVE T2,NUMBER ;Load number into T2.
MOVEI T3,^D10 ;Decimal output.
NOUT% ;And print the number.
ERJMP ERROR ; On error, go to ERROR.
 
;; End program:
 
HALTF% ;Halt program.
JRST GO ;Allow for 'continue'-command.
 
;;
;; The following routine prints out an error message,
;; similar to perror() in C:
;;
 
ERROR: MOVEI T1,.PRIOU ;Standard output.
MOVE T2,[.FHSLF,,-1] ;Own program, last error.
SETZ T3, ;No size-limit on message.
ERSTR% ;Print error-message.
JFCL ; Ignore errors from ERSTR.
JFCL ; dito.
HALTF% ;Halt program.
JRST GO ;Allow for 'continue'-command.
 
END GO
</syntaxhighlight>
Example output:
<pre>
@ exec uinput
MACRO: User
LINK: Loading
[LNKXCT USER execution]
Please type a string, 80 chars max.: This is a test.
Please type the decimal number 75000: 74998
Number is not 75000! Please type the decimal number 75000: 74999
Number is not 75000! Please type the decimal number 75000: 75000
This is a test.
75000
@ _
</pre>
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">printf("String:"); string_value := readline();
printf("Integer: "); int_value := parse(readline());</langsyntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">mystring = InputString["give me a string please"];
myinteger = Input["give me an integer please"];</langsyntaxhighlight>
 
=={{header|MATLAB}}==
Line 1,485 ⟶ 1,705:
 
Sample usage:
<langsyntaxhighlight MATLABlang="matlab">>> input('Input string: ')
Input string: 'Hello'
 
Line 1,504 ⟶ 1,724:
ans =
 
75000</langsyntaxhighlight>
 
=={{header|Maxima}}==
 
<syntaxhighlight lang="maxima">
/* String routine */
block(
s:read("enter a string"),
if stringp(s) then print(s,"is an actual string") else "that is not a string")$
 
/* Number routine */
block(
n:read("enter a number"),
if numberp(n) then print(n,"is an actual number") else "that is not a number")$
</syntaxhighlight>
 
=={{header|Metafont}}==
 
<langsyntaxhighlight lang="metafont">string s;
message "write a string: ";
s := readstring;
Line 1,519 ⟶ 1,753:
message "Sorry..."
fi;
end</langsyntaxhighlight>
 
If we do not provide a number in the second input, Metafont will complain. (The number 75000 was reduced to 750 since Metafont biggest number is near 4096).
Line 1,525 ⟶ 1,759:
=={{header|min}}==
{{works with|min|0.19.3}}
<langsyntaxhighlight lang="min">"Enter a string" ask
"Enter an integer" ask int</langsyntaxhighlight>
 
=={{header|Mirah}}==
<langsyntaxhighlight lang="mirah">s = System.console.readLine()
 
puts s</langsyntaxhighlight>
 
=={{header|mIRC Scripting Language}}==
<langsyntaxhighlight lang="mirc">alias askmesomething {
echo -a You answered: $input(What's your name?, e)
}</langsyntaxhighlight>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE Input EXPORTS Main;
 
IMPORT IO, Fmt;
Line 1,552 ⟶ 1,786:
number := IO.GetInt();
IO.Put("You entered: " & string & " and " & Fmt.Int(number) & "\n");
END Input.</langsyntaxhighlight>
 
=={{header|MUMPS}}==
<langsyntaxhighlight MUMPSlang="mumps">TXTINP
NEW S,N
WRITE "Enter a string: "
Line 1,562 ⟶ 1,796:
READ N,!
KILL S,N
QUIT</langsyntaxhighlight>
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">string = str(input("Enter a string: "))
integer = int(input("Enter an integer: "))</langsyntaxhighlight>
 
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
User input/Text, in Neko
Tectonics:
Line 1,603 ⟶ 1,837:
if num == 75000 $print("Rosetta Code 75000, for the win!\n")
else $print("Sorry, need 75000\n")
} catch problem $print("Exception: ", problem, "\n")</langsyntaxhighlight>
 
{{out}}
Line 1,615 ⟶ 1,849:
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">using System;
using System.Console;
 
Line 1,634 ⟶ 1,868:
} while ((!numeric) || (entry != 75000))
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
 
Line 1,654 ⟶ 1,888:
end
return
</syntaxhighlight>
</lang>
 
=={{header|newLISP}}==
{{works with|newLISP|9.0}}
<langsyntaxhighlight lang="lisp">(print "Enter an integer: ")
(set 'x (read-line))
(print "Enter a string: ")
(set 'y (read-line))</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import rdstdin, strutils
 
let str = readLineFromStdin "Input a string: "
let num = parseInt(readLineFromStdin "Input an integer: ")</langsyntaxhighlight>
 
=={{header|NS-HUBASIC}}==
<langsyntaxhighlight NSlang="ns-HUBASIChubasic">10 INPUT "ENTER A STRING: ",STRING$
20 PRINT "YOU ENTERED ";STRING$;"."
30 INPUT "ENTER AN INTEGER: ",INTEGER
40 PRINT "YOU ENTERED";INTEGER;"."</langsyntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
{
String: (input "Enter a string: ")
Number: (input "Enter an integer: ")
}
</syntaxhighlight>
{{out}}
<pre>
Enter a string: Hello world!
Enter an integer: 75000
╭────────┬──────────────╮
│ String │ Hello world! │
│ Number │ 75000 │
╰────────┴──────────────╯
</pre>
 
=={{header|Oberon-2}}==
{{works with|oo2c}}
<langsyntaxhighlight lang="oberon2">
MODULE InputText;
IMPORT
Line 1,689 ⟶ 1,940:
Out.String("Enter a string: ");Out.Flush();In.String(str);
END InputText.
</syntaxhighlight>
</lang>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
use IO;
 
Line 1,706 ⟶ 1,957:
}
}
</syntaxhighlight>
</lang>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">print_string "Enter a string: ";
let str = read_line () in
print_string "Enter an integer: ";
let num = read_int () in
Printf.printf "%s%d\n" str num</langsyntaxhighlight>
 
=={{header|Octave}}==
 
<langsyntaxhighlight lang="octave">% read a string ("s")
s = input("Enter a string: ", "s");
 
Line 1,731 ⟶ 1,982:
disp(s);
disp(i);
disp(ri);</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">import: console
 
: testInput{
Line 1,742 ⟶ 1,993:
while (System.Console askln asInteger dup ->n isNull) [ "Not an integer" println ]
 
System.Out "Received : " << s << " and " << n << cr ;</langsyntaxhighlight>
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">declare
StdIn = {New class $ from Open.file Open.text end init(name:stdin)}
StringInput
Line 1,758 ⟶ 2,009:
in
Num := try {String.toInt Line} catch _ then 0 end
end</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">s=input();
n=eval(input());</langsyntaxhighlight>
 
=={{header|Pascal}}==
 
<langsyntaxhighlight lang="pascal">program UserInput(input, output);
var i : Integer;
s : String;
Line 1,774 ⟶ 2,025:
write('Enter a string: ');
readln(s)
end.</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">print "Enter a string: ";
my $string = <>;
print "Enter an integer: ";
my $integer = <>;</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">prompt_string</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Enter any string:"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">prompt_number</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Enter the number 75000:"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">75000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">75000</span><span style="color: #0000FF;">})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,796 ⟶ 2,047:
75000
</pre>
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: https://rosettacode.org/wiki/User_input/Text
by Galileo, 10/2022 #/
 
"Enter any string: " input nl
true while
75000 "Enter the number " over tostr chain ": " chain input
nl tonum over == not
endwhile
drop pstack</syntaxhighlight>
{{out}}
<pre>Enter any string: Hello
Enter the number 75000: 1000
Enter the number 75000: 75000
 
["Hello", 75000]
 
=== Press any key to exit ===</pre>
 
=={{header|PHP}}==
{{works with|CLI SAPI}}
<langsyntaxhighlight lang="php">#!/usr/bin/php
<?php
$string = fgets(STDIN);
$integer = (int) fgets(STDIN);</langsyntaxhighlight>
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">main =>
print("Enter a string: "),
String = read_line(),
print("Enter a number: "),
Number = read_int(),
println([string=String,number=Number]).</syntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(in NIL # Guarantee reading from standard input
(let (Str (read) Num (read))
(prinl "The string is: \"" Str "\"")
(prinl "The number is: " Num) ) )</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight lang="pike">int main(){
write("Enter a String: ");
string str = Stdio.stdin->gets();
write("Enter 75000: ");
int num = Stdio.stdin->gets();
}</langsyntaxhighlight>
 
=={{header|PL/I}}==
<langsyntaxhighlight PLlang="pl/Ii">declare s character (100) varying;
declare k fixed decimal (15);
 
Line 1,829 ⟶ 2,107:
get list (k);
put skip list (k);
put skip list ('Thanks');</langsyntaxhighlight>
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Demonstrate input.
Line 1,845 ⟶ 2,123:
\Now show the input values
Write "The string: " then the string to the console.
Write "The number: " then the number to the console.</langsyntaxhighlight>
A sample run of the program:
{{out}}
Line 1,856 ⟶ 2,134:
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">;;; Setup item reader
lvars itemrep = incharitem(charin);
lvars s, c, j = 0;
Line 1,864 ⟶ 2,142:
consstring(j) -> s;
;;; read the integer
lvars i = itemrep();</langsyntaxhighlight>
 
=={{header|PostScript}}==
{{works with|PostScript|level-2}}
<langsyntaxhighlight lang="postscript">%open stdin for reading (and name the channel "kbd"):
/kbd (%stdin) (r) file def
%make ten-char buffer to read string into:
/buf (..........) def
%read string into buffer:
kbd buf readline</langsyntaxhighlight>
 
At this point there will be two items on the stack: a boolean which is "true" if the read was successful and the string that was read from the kbd (input terminates on a <return>). If the length of the string exceeds the buffer length, an error condition occurs (rangecheck). For the second part, the above could be followed by this:
 
<langsyntaxhighlight lang="postscript">%if the read was successful, convert the string to integer:
{cvi} if</langsyntaxhighlight>
 
which will read the conversion operator 'cvi' (convert to integer) and the boolean and execute the former if the latter is true.
Line 1,884 ⟶ 2,162:
=={{header|PowerShell}}==
 
<langsyntaxhighlight lang="powershell">$string = Read-Host "Input a string"
[int]$number = Read-Host "Input a number"</langsyntaxhighlight>
 
=={{header|PureBasic}}==
 
<langsyntaxhighlight PureBasiclang="purebasic">If OpenConsole()
; Declare a string and a integer to be used
Define txt.s, num.i
Line 1,904 ⟶ 2,182:
Print("You made it!")
Delay(3000): CloseConsole()
EndIf</langsyntaxhighlight>
 
=={{header|Python}}==
===Input a string===
<langsyntaxhighlight lang="python"> string = raw_input("Input a string: ")</langsyntaxhighlight>
In Python 3.0, raw_input will be renamed to input(). The Python 3.0 equivalent would be
<langsyntaxhighlight lang="python"> string = input("Input a string: ")</langsyntaxhighlight>
===Input a number===
While input() gets a string in Python 3.0, in 2.x it is the equivalent of eval(raw_input(...)). Because this runs arbitrary code, and just isn't nice, it is being removed in Python 3.0. raw_input() is being changed to input() because there will be no other kind of input function in Python 3.0.
<langsyntaxhighlight lang="python"> number = input("Input a number: ") # Deprecated, please don't use.</langsyntaxhighlight>
Python 3.0 equivalent:
<langsyntaxhighlight lang="python"> number = eval(input("Input a number: ")) # Evil, please don't use.</langsyntaxhighlight>
The preferred way of getting numbers from the user is to take the input as a string, and pass it to any one of the numeric types to create an instance of the appropriate number.
<langsyntaxhighlight lang="python"> number = float(raw_input("Input a number: "))</langsyntaxhighlight>
Python 3.0 equivalent:
<langsyntaxhighlight lang="python"> number = float(input("Input a number: "))</langsyntaxhighlight>
float may be replaced by any numeric type, such as int, complex, or decimal.Decimal. Each one varies in expected input.
 
Line 1,926 ⟶ 2,204:
The word <code>$->n</code> attempts to convert a string to an integer, and returns an integer and a success flag. Validating the input is not part of the task, but since the flag is there we might as well use it. Similarly, might as well trim leading and trailing spaces, because ''users'', eh.
 
<langsyntaxhighlight Quackerylang="quackery">$ "Please enter a string: " input
say 'You entered: "' echo$ say '"' cr cr
Line 1,935 ⟶ 2,213:
else
[ say "That was not an integer." cr
drop ]</langsyntaxhighlight>
 
{{out}}
Line 1,949 ⟶ 2,227:
{{works with|R|2.81}}
 
<langsyntaxhighlight Rlang="r">stringval <- readline("String: ")
intval <- as.integer(readline("Integer: "))</langsyntaxhighlight>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
(printf "Input a string: ")
Line 1,970 ⟶ 2,248:
(unless (number? n) (error "I said a number!"))
(printf "You entered: ~a\n" n)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my $str = prompt("Enter a string: ");
my $int = prompt("Enter a integer: ");</langsyntaxhighlight>
 
=={{header|Rascal}}==
It is possible to use the eclipse IDE to create consoles. However, just as with the graphical input, this will always return a string. This string can subsequently be evaluated. A very simple example would be:
<langsyntaxhighlight lang="rascal">import util::IDE;
public void InputConsole(){
x = "";
Line 1,986 ⟶ 2,264:
str (str inp) {x = "<inp == "75000" ? "You entered 75000" : "You entered a string">";
return "<x>\n<inp>\nInput\>";});
}</langsyntaxhighlight>
Which has as output:
 
Line 1,994 ⟶ 2,272:
 
=={{header|Raven}}==
<langsyntaxhighlight lang="raven">'Input a string: ' print expect as str
'Input an integer: ' print expect 0 prefer as num</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Textual User Input"
URL: http://rosettacode.org/wiki/User_Input_-_text
Line 2,024 ⟶ 2,302:
; It always pays to be polite...
 
print rejoin [ "Thank you. Your string was '" s "'."]</langsyntaxhighlight>
 
Output:
Line 2,040 ⟶ 2,318:
 
=={{header|Red}}==
<langsyntaxhighlight Redlang="red">n: ask "Please enter # 75000: " str: ask "Please enter any string: "</langsyntaxhighlight>
 
=={{header|Retro}}==
<langsyntaxhighlight Retrolang="retro">:example ("-)
'Enter_a_string:_ s:put s:get s:keep
[ 'Enter_75000:_ s:put s:get-word s:to-number nl #75000 eq? ] until
'Your_string_was:_'%s'\n s:format s:put ;</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 2,061 ⟶ 2,339:
do until userNumber==75000
 
<langsyntaxhighlight lang="rexx">/*REXX program prompts & reads/obtains a string, and also the number 75000 from terminal*/
say 'Please enter a string:' /*issue a prompt message to the term. */
parse pull userString /*the (char) string can be any length. */
Line 2,070 ⟶ 2,348:
parse pull userNumber /*obtain the user text from terminal. */
end /*until*/ /*check if the response is legitimate. */
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see "Enter a string : " give s
see "Enter an integer : " give i
see "String = " + s + nl
see "Integer = " + i + nl
</syntaxhighlight>
</lang>
 
=={{header|Robotic}}==
<langsyntaxhighlight lang="robotic">
input string "Enter string:"
set "$str" to "input"
Line 2,090 ⟶ 2,368:
[ "&number&"
end
</syntaxhighlight>
</lang>
 
To ensure that a specific number must be entered, just create a loop around the second input function:
<langsyntaxhighlight lang="robotic">
input string "Enter string:"
set "$str" to "input"
Line 2,104 ⟶ 2,382:
[ "&number&"
end
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
≪ <span style="color:red">"Enter text" { "" 𝛼 }</span> INPUT <span style="color:grey">@ Set keyboard alpha mode</span>
<span style="color:red">75000</span> → string n75000
≪ '''DO'''
<span style="color:red">"Enter number "</span> n + <span style="color:red">""</span> INPUT
'''UNTIL''' n →STR == '''END'''
string number
≫ ≫ '<span style="color:blue">TASK</span>' STO
 
=={{header|Ruby}}==
{{works with|Ruby|1.8.4}}
<langsyntaxhighlight lang="ruby">print "Enter a string: "
s = gets
printf "Enter an integer: "
Line 2,116 ⟶ 2,403:
puts "String = #{s}"
puts "Integer = #{i}"
puts "Float = #{f}"</langsyntaxhighlight>
 
=={{header|Rust}}==
This program shows all the proper error handling.
<langsyntaxhighlight lang="rust">use std::io::{self, Write};
use std::fmt::Display;
use std::process;
Line 2,151 ⟶ 2,438:
let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
process::exit(code)
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">print("Enter a number: ")
val i=Console.readLong // Task says to enter 75000
print("Enter a string: ")
val s=Console.readLine</langsyntaxhighlight>
 
=={{header|Scheme}}==
The <tt>read</tt> procedure is R5RS standard, inputs a scheme representation so, in order to read a string, one must enter <tt>"hello world"</tt>
<langsyntaxhighlight lang="scheme">(define str (read))
(define num (read))
(display "String = ") (display str)
(display "Integer = ") (display num)</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 2,178 ⟶ 2,465:
write("Enter a string: ");
readln(string_input);
end func;</langsyntaxhighlight>
 
=={{header|Sidef}}==
Using the '''read(Type)''' built-in function:
<langsyntaxhighlight lang="ruby">var s = read(String);
var i = read(Number); # auto-conversion to a number</langsyntaxhighlight>
 
or using the '''Sys.readln(msg)''' method:
<langsyntaxhighlight lang="ruby">var s = Sys.readln("Enter a string: ");
var i = Sys.readln("Enter a number: ").to_i;</langsyntaxhighlight>
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">print: (query: 'Enter a String: ').
[| n |
n: (Integer readFrom: (query: 'Enter an Integer: ')).
Line 2,196 ⟶ 2,483:
ifTrue: [print: n]
ifFalse: [inform: 'Not an integer: ' ; n printString]
] do.</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">'Enter a number: ' display.
a := stdin nextLine asInteger.
 
'Enter a string: ' display.
b := stdin nextLine.</langsyntaxhighlight>
 
=={{header|smart BASIC}}==
Line 2,209 ⟶ 2,496:
'''NOTE:''' The INPUT command uses a colon (:) as opposed to a comma (,) or semi-conlon (;) like other forms of BASIC.
 
<langsyntaxhighlight lang="qbasic">INPUT "Enter a string.":a$
INPUT "Enter the value 75000.":n</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
<langsyntaxhighlight lang="snobol4"> output = "Enter a string:"
str = trim(input)
output = "Enter an integer:"
int = trim(input)
output = "String: " str " Integer: " int
end</langsyntaxhighlight>
 
=={{header|SPL}}==
In SPL all console input is text, so number should be converted from text using #.val function.
<langsyntaxhighlight lang="spl">text = #.input("Input a string")
number = #.val(#.input("Input a number"))</langsyntaxhighlight>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "get_string" )
@( description, "Input a string and the integer 75000 from the text console." )
@( see_also, "https://rosettacode.org/wiki/User_input/Text" )
@( author, "Ken O. Burtch" );
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure get_string is
s : unbounded_string;
i : integer;
begin
s := get_line;
i := integer( numerics.value( get_line ) );
? s @ i;
exception when others =>
put_line( standard_error, "the value is not valid" );
end get_string;</syntaxhighlight>
As a unstructured script and no exception handling.
<syntaxhighlight lang="ada">
s := get_line;
i := numerics.value( get_line );
? s @ i;</syntaxhighlight>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">print "Enter a string: ";
let val str = valOf (TextIO.inputLine TextIO.stdIn) in (* note: this keeps the trailing newline *)
print "Enter an integer: ";
Line 2,232 ⟶ 2,547:
print (str ^ Int.toString num ^ "\n")
end
end</langsyntaxhighlight>
 
=={{header|Swift}}==
{{works with|Swift|2.x+}}
<langsyntaxhighlight lang="swift">print("Enter a string: ", terminator: "")
if let str = readLine() {
print(str)
}</langsyntaxhighlight>
{{works with|Swift|5.x+}}
<langsyntaxhighlight lang="swift">print("Enter a string: ", terminator: "")
guard let str = readLine() else {
fatalError("Nothing read!")
Line 2,250 ⟶ 2,565:
fatalError("Not a number!")
}
print(num)</langsyntaxhighlight>
 
=={{header|Tcl}}==
Like LISP, there is no concept of a "number" in Tcl - the only real variable type is a string (whether a string might represent a number is a matter of interpretation of the string in a mathematical expression at some later time). Thus the input is the same for both tasks:
<langsyntaxhighlight lang="tcl">set str [gets stdin]
set num [gets stdin]</langsyntaxhighlight>
possibly followed by something like
<langsyntaxhighlight lang="tcl">if {![string is integer -strict $num]} then { ...do something here...}</langsyntaxhighlight>
 
If the requirement is to prompt until the user enters the integer 75000, then:
<langsyntaxhighlight lang="tcl">set input 0
while {$input != 75000} {
puts -nonewline "enter the number '75000': "
flush stdout
set input [gets stdin]
}</langsyntaxhighlight>
 
Of course, it's nicer to wrap the primitives in a procedure:
<langsyntaxhighlight lang="tcl">proc question {var message} {
upvar 1 $var v
puts -nonewline "$message: "
Line 2,276 ⟶ 2,591:
question name "What is your name"
question task "What is your quest"
question doom "What is the air-speed velocity of an unladen swallow"</langsyntaxhighlight>
 
=={{header|TI-83 BASIC}}==
Line 2,282 ⟶ 2,597:
This program leaves the string in String1, and the integer in variable "i".
 
<langsyntaxhighlight lang="ti83b">
:Input "Enter a string:",Str1
:Prompt i
Line 2,289 ⟶ 2,604:
:Else
:Stop
</syntaxhighlight>
</lang>
 
=={{header|TI-89 BASIC}}==
Line 2,295 ⟶ 2,610:
This program leaves the requested values in the global variables ''s'' and ''integer''.
 
<langsyntaxhighlight lang="ti89b">Prgm
InputStr "Enter a string", s
Loop
Line 2,305 ⟶ 2,620:
EndIf
EndLoop
EndPrgm</langsyntaxhighlight>
 
=={{header|Toka}}==
<langsyntaxhighlight lang="toka">needs readline
." Enter a string: " readline is-data the-string
." Enter a number: " readline >number [ ." Not a number!" drop 0 ] ifFalse is-data the-number
 
the-string type cr
the-number . cr</langsyntaxhighlight>
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
LOOP
Line 2,329 ⟶ 2,644:
ENDIF
ENDLOOP
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,342 ⟶ 2,657:
=={{header|UNIX Shell}}==
{{works with|Bourne Shell}}
<langsyntaxhighlight lang="bash">#!/bin/sh
 
read string
read integer
read -p 'Enter a number: ' number
echo "The number is $number"</langsyntaxhighlight>
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">#
# user input
#
Line 2,363 ⟶ 2,678:
set i (in int console)
 
out "you entered " str " and " i endl console</langsyntaxhighlight>
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Public Sub text()
Debug.Print InputBox("Input a string")
Debug.Print InputBox("Input the integer 75000", "Input an integer", 75000, Context = "Long")
End Sub</langsyntaxhighlight>
 
=={{header|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">Get_Input(1, "Enter a string: ")
#2 = Get_Num("Enter a number: ")</langsyntaxhighlight>
 
=={{header|Visual Basic .NET}}==
Line 2,381 ⟶ 2,696:
 
===Input an Integer===
<langsyntaxhighlight lang="vbnet">Dim i As Integer
Console.WriteLine("Enter an Integer")
i = Console.ReadLine()</langsyntaxhighlight>
 
===Input an Integer With Error Handling===
<langsyntaxhighlight lang="vbnet">Dim i As Integer
Dim iString As String
Console.WriteLine("Enter an Integer")
Line 2,394 ⟶ 2,709:
Catch ex As Exception
Console.WriteLine("This is not an Integer")
End Try</langsyntaxhighlight>
 
===Input a String===
<langsyntaxhighlight lang="vbnet">Dim i As String
Console.WriteLine("Enter a String")
i = Console.ReadLine()</langsyntaxhighlight>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">import os
 
fn main() {
s := os.input('Enter string').int()
if s == 75000 {
println('good')
} else {
println('bad')
}
}</syntaxhighlight>
 
==Input conversion with Error Handling==
<syntaxhighlight lang="text">import os
import strconv
 
fn main() {
s := strconv.atoi(os.input('Enter string')) ?
if s == 75000 {
println('good')
} else {
println('bad $s')
}
}</syntaxhighlight>
 
=={{header|Wee Basic}}==
<syntaxhighlight lang="text">print 1 "Enter a string."
input string$
print 1 "Enter an integer."
input integer</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight ecmascriptlang="wren">import "io" for Stdin, Stdout
 
var string
Line 2,436 ⟶ 2,776:
System.print("\nYou entered:")
System.print(" string: %(string)")
System.print(" number: %(number)")</langsyntaxhighlight>
 
{{out}}
Line 2,450 ⟶ 2,790:
=={{header|XLISP}}==
<tt>READ-LINE</tt> reads a line of input as a string; <tt>READ</tt> reads an expression, of arbitrary complexity.
<langsyntaxhighlight lang="scheme">(display "Enter a string: ")
(define s (read-line))
(display "Yes, ")
Line 2,465 ⟶ 2,805:
"That is not the integer 75000." )
(t
"Yes, that is the integer 75000." ) ) )</langsyntaxhighlight>
{{out}}
<pre>Enter a string: Rosetta Code
Line 2,480 ⟶ 2,820:
place of the Enter key to mark the end of the string.
 
<langsyntaxhighlight XPL0lang="xpl0">string 0; \use zero-terminated strings, instead of MSb terminated
include c:\cxpl\codes;
int I;
Line 2,494 ⟶ 2,834:
Text(0, "Howdy "); Text(0, Name); Text(0, "! Now please enter ^"75000^": ");
IntOut(0, IntIn(0)); CrLf(0); \echo the number
]</langsyntaxhighlight>
 
Example output:
Line 2,504 ⟶ 2,844:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">str:=ask("Gimmie a string: ");
n:=ask("Type 75000: ").toInt();</langsyntaxhighlight>
 
=={{header|ZX Spectrum Basic}}==
 
<langsyntaxhighlight lang="basic">10 INPUT "Enter a string:"; s$
20 INPUT "Enter a number: "; n</langsyntaxhighlight>
 
{{omit from|GUISS|We need an application that asks for these}}
18

edits