A+B: Difference between revisions

Content added Content deleted
m (fixed V to point to correct lang (title vlang in rosetta code) and re-ordered it)
Line 3,698: Line 3,698:
PRINT "A + B = " + LTRIM$(STR$(c))
PRINT "A + B = " + LTRIM$(STR$(c))
</lang>
</lang>

'''Fully implemented version:'''
<br>
''CBTJD'': 2020/03/13
----
* Task description requires:
** Both integers entered on one line.
** Integers between -1000 and +1000.
<lang vb>START:
PRINT "Enter two integers between -1000 and +1000 separated by at least one space: "
LINE INPUT "> "; n$ ' | LINE INPUT allows entry of space and other non-numeric characters
n$ = _TRIM$(n$) ' | TRIM any leading or trailing spaces.
bpos = INSTR(n$, " ") ' | Find the first space between the two numbers.
a = VAL(LEFT$(n$, bpos - 1)) ' | Parse the first number from the input string.
b = VAL(_TRIM$(MID$(n$, bpos))) ' | Parse the second number from the input string.
IF (a < -1000 OR a > 1000) OR (b < -1000 OR b > 1000) THEN
PRINT "A number is outside of limit (-1000 to +1000). Try again.": PRINT
GOTO START ' | Check both number are within prescribed limit.
END IF
a$ = LTRIM$(STR$(a)) ' | Clean up both numbers and the sum for better printing.
b$ = LTRIM$(STR$(b)) ' | "
sum$ = LTRIM$(STR$(a + b)) ' | "
PRINT "The sum of the two integers a + b = "; a$; " + "; b$; " = "; sum$</lang>


=={{header|Quite BASIC}}==
=={{header|Quite BASIC}}==