Register    Login    Forum    Search    FAQ

Board index » Programming » Visual Basic




 Page 1 of 1 [ 3 posts ] 



Author Message
 Post subject: How to make conditions without using if else, loops, and mod
 Post Posted: Sun Jan 27, 2013 6:07 am 
Offline
Novice User
Novice User

Joined: Wed Jan 26, 2011 5:20 am
Posts: 24
Languages: C, C++, Java, HTML, JavaScript, PHP, Assembly, Visual Basic
Text editor: Notepad++
I'm new with Visual Basic. Our professor told us to make two programs. One would determine if a number is odd or even and the other is allowing the user to input the no. of km to get the amount of fare (7.00 for the 1st km and 1.00 for the succeeding km). BUT we are not allowed to use if else statements, loops, and modulus...I'm thinking if using XOR will do it but as of now I can't figure it out. Can somebody give me some hints there...and could somebody tell me if I'm right about using XOR...

PLEASE HELP!!!


Top 
 Post subject: Re: How to make conditions without using if else, loops, and
 Post Posted: Sun Jan 27, 2013 7:31 am 
Offline
Expert Poster
Expert Poster
User avatar

Joined: Fri Aug 10, 2012 7:02 am
Posts: 108
Languages: Dutch... To Lazy to update this every time
Text editor: A Self made one (Coded in C#, recoded in VB)
Find out what it does your self

vbnet code:
 
 Public Function CheckOdd(ByVal NumberToCheck As Integer) As Boolean
        Return ((NumberToCheck And 1) = 0)
   End Function
 


This doesn't Work if you enter a Negative value
vbnet code:
 
Public Function Check(ByVal Km As Integer)
        Return (Km - 1) + 7
    End Function
 


Fix for Entering a not Allowed Number

IIf works like this:
'Expression to test , Do this when True, Do this When false
so, if Km is greater then zero do: (Km-1)+7 else return "Invalid Option"

vbnet code:
 
 Public Function Check(ByVal Km As Integer)
                     'Expression to test ,  Do this when True, Do this When false      
                    Return IIf(Km > 0,(Km - 1) + 7,"Invalid Option")
    End Function
 
 


Top 
 Post subject: Re: How to make conditions without using if else, loops, and
 Post Posted: Mon Jan 28, 2013 1:38 pm 
Offline
Novice User
Novice User

Joined: Wed Jan 26, 2011 5:20 am
Posts: 24
Languages: C, C++, Java, HTML, JavaScript, PHP, Assembly, Visual Basic
Text editor: Notepad++
Thanks!!! :D


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 3 posts ] 




Board index » Programming » Visual Basic


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron