Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Is there an easy way to make these if statements be one?
Author Message
joe333

Posted: Tue Apr 13, 2004 7:16 pm   Post subject: Is there an easy way to make these if statements be one?

Is there an easy way to make these smaller? Like in a loop or something? i'm making a hex to dec convertor.

if input1 = "A" then
input2 := intstr (A)
end if
if input1 = "B" then
input2 := intstr (B)
end if
if input1 = "C" then
input2 := intstr (C)
end if
if input1 = "D" then
input2 := intstr (D)
end if
if input1 = "E" then
input2 := intstr (E)
end if
if input1 = "F" then
input2 := intstr (F)
end if

omni

Posted: Tue Apr 13, 2004 7:42 pm   Post subject: (No subject)

Right off the top of my head, you can make it like

if input1="A" then
'command'
elsif input1="B" then
...
...
so on
end if
That means ONLY ONE of those conditions can be true.
Not sure if intstr(A) will work, that converts an integer to a string. Unless
if 'A' is a variable of integer type, don't think that will work
EDEN-E

Posted: Tue Apr 13, 2004 7:57 pm   Post subject: (No subject)

If you dont want to use 'IF' statement, you can use "CASE"

case input1 of
label "A" : input2 := intstr(A)
label "B" : input2 := intstr(B)
label "C" : input2 := intstr(C)
label "D" : input2 := intstr(D)
label "E" : input2 := intstr(E)
label "F" : input2 := intstr(F)
end case
Raugrist

Posted: Tue Apr 13, 2004 8:07 pm   Post subject: (No subject)

I don't know why you're doing intstr, but whatever...

 code: if ord (input1) >= 65 and ord (input2) <= 70 then     input2 := intstr (ord (input1) - 65 + 10) end if

From the looks of your post, that should do it quite nicely. Basically, it checks if input1 is a letter between A and F, and if it is, it gets the number value for that letter (you are converting from Hex, so A = 11, B = 12, ..., F = 15), converting the value to a string and putting it in input2.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: