User input/Text: Difference between revisions

→‎{{header|BabyCobol}}: conform to the task definition
(→‎{{header|BabyCobol}}: conform to the task definition)
(17 intermediate revisions by 11 users not shown)
Line 488:
Disp "That isn't 7500"
End</syntaxhighlight>
 
=={{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 693 ⟶ 709:
number = Str2int( Input ( NULL, 6 ) );
}Stack_off;
 
Free secure text;
Prnl;
End
Line 930 ⟶ 946:
 
=={{header|Elena}}==
ELENA 46.x :
<syntaxhighlight lang="elena">import extensions;
Line 936 ⟶ 952:
{
var num := new Integer();
console.write:("Enter an integer: ").loadLineTo:(num);
var word := console.write:("Enter a String: ").readLine()
}</syntaxhighlight>
 
Line 1,106 ⟶ 1,122:
s = input["Enter a string: "]
i = parseInt[input["Enter an integer: "]]
</syntaxhighlight>
 
=={{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>
 
Line 1,387 ⟶ 1,424:
} while (number != 75000)
}</syntaxhighlight>
 
=={{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}}==
Line 1,426 ⟶ 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}}==
Line 1,654 ⟶ 1,725:
 
75000</syntaxhighlight>
 
=={{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}}==
Line 1,823 ⟶ 1,908:
30 INPUT "ENTER AN INTEGER: ",INTEGER
40 PRINT "YOU ENTERED";INTEGER;"."</syntaxhighlight>
 
=={{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}}==
Line 2,281 ⟶ 2,383:
end
</syntaxhighlight>
 
=={{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}}==
Line 2,400 ⟶ 2,511:
<syntaxhighlight lang="spl">text = #.input("Input a string")
number = #.val(#.input("Input a number"))</syntaxhighlight>
 
=={{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}}==
Line 2,609 ⟶ 2,748:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin, Stdout
 
var string
18

edits