Archive

Archive for November, 2011

What I’ve been working on for the past week ‘-‘

November 26, 2011 Leave a comment

QBasic Tutorial 7 If Statements and Syntax

Some beginning Syntax:

IF<Condition> THEN  Do Something

ELSEIF<Conditon>THEN  Do Something

Else  Do Something

END IF

The Relational Operators

< Less Than

<= Less Than Or Equal To

> Greater Than

>=Greater Than Or Equal To

= Equal To

<> Not Equal To

Starting with a simple if statement:

If 5 > 2 THEN  Print “5 IS Greater Than 2” End IF

5 Is Greater Than 2 Appears which that statement is true.

If we replace the > sign with a < then this statement is not true and nothing pops up in the preview box.

Ex. IF 5 > 10 THEN     PRINT “5 is greater than 10” ELSE     PRINT “5 is less than 10” END IF

Now we’re gonig to have the user enter in two integers and we will check to see which integer is larger than the other.

So we start:

DIM Num1 AS INTEGER DIM Num2 AS INTEGER

CLS

INPUT “Enter First Integer: “, Num1 INPUT “Enter Second Integer: “, Num2

IF Num1 > Num2 THEN     PRINT Num1; “Is Greater Than”; Num2 ELSE     PRINT Num2; “Is Greater Than”; Num1 END IF

Try entering the integers 10 and 10

You get a respose 10 is greater than 10 and that’s not true so let’s have a look at that.

Change this by placing an Else IF statement.

Ex.

DIM Num1 AS INTEGER DIM Num2 AS INTEGER

CLS

INPUT “Enter First Integer: “, Num1 INPUT “Enter Second Integer: “, Num2

IF Num1 > Num2 THEN     PRINT Num1; “Is Greater Than”; Num2 ELSE*if Num2 > Num1 then     PRINT Num2; “Is Greater Than”; Num1 ELSE      —There is only 3 possible                          situations here.  Print “The numbers are the same”                —Num1 is Greater than Num2,Num2 is                                                     Greater than Num1, or that the     End IF                                             numbers are the same.

So the finaly code:

DIM Num1 AS INTEGER DIM Num2 AS INTEGER

CLS

INPUT “Enter First Integer: “, Num1 INPUT “Enter Second Integer: “, Num2

IF Num1 > Num2 THEN     PRINT Num1; “Is Greater Than”; Num2 ELSEIF Num2 > Num1 THEN     PRINT Num2; “Is Greater Than”; Num1 ELSE     PRINT “The Numbers Are The Same” END IF

What I’ve been working on for the past week ‘-‘

November 26, 2011 Leave a comment

Qbasic Tutorial 6 -User Input-

Declare Varible Num2 as Integer

Program Asking the user to input their first and last name

So 2 variables one called FirstName and the second called LastName

Declare FirstName as a string as well with the LastName

Get the user input by placing the command INPUT then the actual prompt ex.”Enter First Name: “

Ex. Input “Enter First Name: “, FirstName     Input “Enter Last Name: “, LastName

Note-If you replace the commas here with ; it places a ? after Enter First Name

print the output “Nice to meet you, ” ; FirstName; ” ” ; LastName

Then we modify the program to ask the user to enter 2 numbers so you can add them together.

This is done by declaring Num1 as an Integer by:

DIM Num1 AS INTEGER

Doing the same for the second variable Num2

DIM Num2 AS INTEGER

Now we get the input from the user promting the user to enter the first integer.

Doing this by Input “Enter First Integer: “, Num1

Same with the second integer

Input “Enter Second Integer: “, Num2

Now we print the output as:

Print Num1; ” + “; Num2; ” = “; Num1 + Num2

Example: So is the user enters in 10 as the first number and 20 as the second variable. We would get 10 plus 20 = 10 plus 20 (the actual calculation)

What I’ve been working on for the past week ‘-‘

November 26, 2011 Leave a comment

QBasic 1.1

Variables and Data Types QB64 Tutorial 4

Variables:

-Hold data in memory

-Are assigned a data type

-The data can change throughout the program’s operation

-The data entered must be the same data type as assigned to the variable

Qbasic 1.1 Data Types

String……..Text and Characters

Integer…………..Non-Floating-Point

-32,768 to 32,767

Long…………..Non-Floating-Point

-2,147,483,648 to 2,147,483,647

Single…………Floating Point

-1.67×10^308 to 1.67×10^308

Note: QBasic 1.1 May have a problem with computations involving double data types

*Updated* Data types

_Integer64   &&

-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

_Float       ##

-1.18×10^4932 to 1.18×10^4932

Info on all data types go to: http://www.qb64.net/wiki/index.php?title=Data_types

*Header$ in this example is a string

*Num1% in this example is an integer to = 5

*Num2% is an integer to = 6

*Num3% is a long integer = to 45000

*Num4% is also a long integer set to =  54000

*Num5! (Single) = 4.5

*Num6! = 6.75

*Num7# is a double data type set(Double Integer)?I believe? to = 56000.25

*Num8# is another double data type set to 89000.34

He then prints the header

Then prints some calculations

*This is a way to declare variables*

Another way to declare variables- You can use this in visual basic as well*

%d bloggers like this: