answersLogoWhite

0

USING STRING LITERAL VALUES TO ADD 2 NUMBERS

If you just want to show the outcome of two numbers you have:

PRINT 4 + 5

This will print '9' the answer to 4 + 5.

If you want to show the addition:

PRINT "4 + 5 = "; 4 + 5

This will show the question and then calculate the answer.

If you want the user to input numbers to add, use variables and then add them the same way.

======

COLLECTING USER INPUT FROM THE KEYBOARD/USING NUMERIC VARIABLES

In the following example, the end user can get to interact with the program by typing in their numbers at the keyboard; then, pressing the [Enter] key.

CLS

PRINT "PROGRAM: Add 2 numbers"

PRINT

INPUT "Enter the 1st number: ", number1

INPUT "Enter the 2nd number: ", number2

PRINT

sumTotal=number1+number2

PRINT "The sum total is: "; sumTotal

PRINT

INPUT "Again, Y/N"; yesNo$

IF UCASE$(LEFT$(yesNo$,1))="Y" THEN RUN

END

======

CREATE FUNCTION/THEN, MAKE A FUNCTION CALL TO ADD 2 NUMBERS

Another way to write this program is to create a function/then, make a function call...

'*** PROGRAM: Add 2 numbers...

'*** Variable declaration list...

number1=7 '...initialise numeric variable 1

number2=3 '...initialise numeric variable 2

'*** Main program...

CLS '...(CL)ear the (S)creen

PRINT add(number1,number2) '...make function call/passing in 2 numbers to add

END '...END of program/halt program code execution

'*** Function(s)...

FUNCTION add(num1,num2) '...this line marks the start of the Function

add=num1+num2 '...this line returns the sum total of the 2 numbers

END FUNCTION '...this line marks the end of the Function

User Avatar

Onie Koch

Lvl 10
∙ 4y ago
User Avatar

What else can I help you with?

Related Questions

Write a C program to print the following series 112 122 . 1n2?

write a program to print the series 1/12+1/22+.........+1/n2 ?


Write a unix program to print print a pattern?

echo 'print a pattern'


Write an assembly language program to print a to z on screen?

write a program to print A to Z on screen in c?


Which is a program embedded in firmware that manages print jobs?

Print Server


How do you print from compaq laptop?

Use the option File / Print in the program you are using.


Write in BlueJ to print lucky numbers?

To print lucky numbers in java, you must give the following program: class example { static public void main(String[] args) { System.out.println("Lucky number is your favourite number which is your DOB"); } }


How do you print the answer you get?

Select the answer, copy and paste into a word processing program, and print as you would print any other document.


How to print a jet airways ticket?

If your screen does not give you an option to Print then save the document to a word program and print from there.


Q2 Write a program to print even numbers between 10 and 50?

You can use int i; for (i = 10; i <= 50; i += 2) {//print i} as a program to print even numbers between 10 and 50.


How do you go to print preview?

It depends on the program, but usually it's in the "Print" dialogue box.


What is java program on computers?

#!/usr/bin/perl print 'java program';


What is the program in QBASIC to print the following series 1 4 9 16?

10 CLS: PRINT "I shall now amaze the audience by printing " 20 PRINT "the four smallest perfect square integers." 30 for N = 1 to 4 : PRINT N, N^2 : NEXT N 40 PRINT: PRINT "Thank you." 50 PRINT "You've been a wonderful audience." 60 PRINT "I'm here until Friday." 70 PRINT "Don't forget to tip your waiter."