Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
NeatSquidYT

Problem with a Small Basic program

Recommended Posts

Posted · Original PosterOP

Hi, I was doing my homework on "Comparing Three Numbers". For some reason, it ALWAYS picks number 3 for some reason, for both smallest and largest, and wondering why it did that.

TextWindow.WriteLine("Please enter your first number")num1 = TextWindow.ReadNumber()TextWindow.WriteLine("Please enter your second number")num2 = TextWindow.ReadNumber()TextWindow.WriteLine("Please enter your third number")num3 = TextWindow.ReadNumber()If num1 > num2 And num3 Then  largest = "Number 1"ElseIf num2 > num1 And num3 Then  largest = "Number 2"Else  largest = "Number 3"EndIfIf num1 < num2 And num3 Then  smallest = "Number 1"ElseIf num2 < num1 And num3 Then  smallest = "Number 2"Else  smallest = "Number 3"EndIf TextWindow.WriteLine("The smallest number was: "+smallest)TextWindow.WriteLine("The largest number was: "+largest)

Help is appreciated


Spoiler

Main PC || CPU - Xeon E3 1231 V3 || Motherboard - MSI Z97 PC Mate || CPU Cooler - Cooler Master Hyper 212 EVO || RAM - 1x8GB HyperX Fury Blue || Graphics card - MSI TwinFrozr V GTX 970 || Storage - 1x BX100 250GB, 1x 1TB WD Blue || PSU - EVGA G2 750W || Case - Corsair 200R

TV PC || CPU - Pentium G3258 @ 4.5GHz 1.2V || Motherboard - MSI H81M-P33 || CPU Cooler - Stock || RAM - 2x4GB random Samsung RAM || Graphics card - Intel HD Graphics (will be R9 390 in a few weeks) || Storage - 1x SanDisk SSD Plus 120GB, 1x Samsung 1.5TB HDD || PSU - Corsair CX600M || Case - None (soon to be Cooler Master Elite 430)

 

Link to post
Share on other sites

Maybe try adding:

"ElseIf num3 > num1 And num2 Then"


Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to post
Share on other sites

i would do something like this

varibles

 

num1, num2, num3, highest, lowest as integer

 

num1 = number input

 

set highest and lowest to num1

 

(otherwise lowest number will come out as 0 as it will default to 0)

 

 

num2 = user input

 

if num2 is < lowest then

lowest = num2

 

if num2 is > highest then

highest = num2

 

num3 = user input

 

if num3 is < lowest then

lowest = num3

 

if num3 is > highest then

highest = num3

 

print out highest and lowest number

 

You can do this with less code, it's what i would start with.

 

What language you coding in?


                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites
Posted · Original PosterOP

i would do something like this

varibles

 

num1, num2, num3, highest, lowest as integer

 

num1 = number input

 

set highest and lowest to num1

 

(otherwise lowest number will come out as 0 as it will default to 0)

 

 

num2 = user input

 

if num2 is < lowest then

lowest = num2

 

if num2 is > highest then

highest = num2

 

num3 = user input

 

if num3 is < lowest then

lowest = num3

 

if num3 is > highest then

highest = num3

 

print out highest and lowest number

 

You can do this with less code, it's what i would start with.

 

What language you coding in?

 

 

What language is it?

Small Basic


Spoiler

Main PC || CPU - Xeon E3 1231 V3 || Motherboard - MSI Z97 PC Mate || CPU Cooler - Cooler Master Hyper 212 EVO || RAM - 1x8GB HyperX Fury Blue || Graphics card - MSI TwinFrozr V GTX 970 || Storage - 1x BX100 250GB, 1x 1TB WD Blue || PSU - EVGA G2 750W || Case - Corsair 200R

TV PC || CPU - Pentium G3258 @ 4.5GHz 1.2V || Motherboard - MSI H81M-P33 || CPU Cooler - Stock || RAM - 2x4GB random Samsung RAM || Graphics card - Intel HD Graphics (will be R9 390 in a few weeks) || Storage - 1x SanDisk SSD Plus 120GB, 1x Samsung 1.5TB HDD || PSU - Corsair CX600M || Case - None (soon to be Cooler Master Elite 430)

 

Link to post
Share on other sites

You cannot say "num1 < num2 and num3" you have to say "num1 < num2 and num1 < num3"

If num1 > num2 And num1 > num3 Then  largest = "Number 1"ElseIf num2 > num1 And num2 > num3 Then  largest = "Number 2"Else  largest = "Number 3"EndIf

--

Link to post
Share on other sites

 

You cannot say "num1 < num2 and num3" you have to say "num1 < num2 and num1 < num3"

If num1 > num2 And num1 > num3 Then  largest = "Number 1"ElseIf num2 > num1 And num2 > num3 Then  largest = "Number 2"Else  largest = "Number 3"EndIf

I would agree with this. The structure would be:

If (Condition is true) And (Condition is true) Then<Do Something>

I've never used small basic but I can only assume that it doesn't return true if a number is more than 0 when used as a boolean.

Link to post
Share on other sites

I would agree with this. The structure would be:

If (Condition is true) And (Condition is true) Then<Do Something>

I've never used small basic but I can only assume that it doesn't return true if a number is more than 0 when used as a boolean.

 

 

 

You cannot say "num1 < num2 and num3" you have to say "num1 < num2 and num1 < num3"

If num1 > num2 And num1 > num3 Then  largest = "Number 1"ElseIf num2 > num1 And num2 > num3 Then  largest = "Number 2"Else  largest = "Number 3"EndIf

I agree with these two :D By saying

If num1 < num2 And num3 Then

it's counting num3 as it's own condition. 

Link to post
Share on other sites


If num1 > Num2 AND Num1 > Num3 Then

Largest="Number 1" ORELSE _

Num2>Num1 AND NUm2> Num3 Then

Largest="Number 2" ORELSE _

Num3>Num1 AND Num3>Num2 Then

Largest="Number 3" Else_

Largest="invaid"

End IF

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

Newegg

×