• 0

create if...elseif statement Visual basic


Question

Write an If..ElseIf  statement (or Select Case if you prefer) given the following:

 

decTicketPrice                    ?ticket price

intAge                                  ?age of customer   

 

If customer's age is less than 6, ticket price is Free

 

If customer's age is 6 to 12, ticket price is $3.50

 

If customer's age is 13 to 19, ticket price is $4.50

 

If customer's age is over 62, ticket price is $5.50

 

Otherwise, ticket price is $7.50

Recommended Posts

  • 0
  On 24/08/2013 at 03:30, soccerstar206 said:

I do know how to do them I just need to do them quickly and I take awhile when I write my code

Just copy and paste, then modify, the examples at my link above.

  • 0
  On 24/08/2013 at 10:11, lunamonkey said:

He wanted it quick, but the time between posts was longer than it would have taken, like 2 minutes.

 

Not even that... In fact, it would have taken longer to type up the OP than write the elseif clause he wanted...

  • 0
  On 24/08/2013 at 16:55, jake1eye said:

Anyone who can not use If statements, case select, or for if loops should not

be in a programming class.

Programming classes are there to teach, are they not? 

 

Although I think if someone has trouble with something this simple, they might want to take up another skill. Like knitting. 

  • 0
  On 24/08/2013 at 23:11, adrynalyne said:

Programming classes are there to teach, are they not? 

 

Although I think if someone has trouble with something this simple, they might want to take up another skill. Like knitting. 

 

Yep, I learned LONG ago that programming was not for me.

  • 0

10 price = 7.50
20 if age > 62 then price = 5.50
30 if age < 20 then price = 4.50
40 if age < 12 then price = 3.50
50 if age < 6 then price = 0

 

Wait, was this supposed to be in Commodore 64 BASIC?

 

(Yes, this is a horrible example of coding, it's deliberate)

  • 0

Some more examples for your education:

 

REXX

/* REXX */
arg intAge .

select
when intAge <   6 then decTicketPrice = 0
when intAge <= 12 then decTicketPrice = 3.5
when intAge <= 19 then decTicketPrice = 4.5
when intAge >  62 then decTicketPrice = 5.5
otherwise              decTicketPrice = 7.5
end

return decTicketPrice

Cobol

01 DECTICKETPRICE			PIC S9(5)V99 COMP-3.
01 INTAGE				PIC 9(3) COMP-3.

EVALUATE TRUE
WHEN INTAGE <  6
	MOVE ZERO TO DECTICKETPRICE
WHEN INTAGE <= 12
	MOVE 3.5  TO DECTICKETPRICE
WHEN INTAGE <= 19
	MOVE 4.5 TO DECTICKETPRICE	
WHEN INTAGE >  62 
	MOVE 5.5 TO DECTICKETPRICE
WHEN OTHER
	MOVE 7.5 TO DECTICKETPRICE
END-EVALUATE.

Easytrieve Plus (v6.4 up)

DECTICKETPRICE				W	4 P 2
INTAGE					W	2 P

IF      INTAGE LT  6
	DECTICKETPRICE = 0
ELSE-IF INTAGE LE 12
	DECTICKETPRICE = 3.5
ELSE-IF INTAGE LE 19
	DECTICKETPRICE = 4.5
ELSE-IF INTAGE GT 62
	DECTICKETPRICE = 5.5
ELSE
	DECTICKETPRICE = 7.5
END-IF
  • 0
  On 24/08/2013 at 22:53, soccerstar206 said:

Thanks for all the help guys! Every one of your helpful comments contributed to me getting an A on the assignment!

 

Now there's a misrepresented grade if ever I saw one.

  • 0

Tbh it seems the OP didn't even try to do this.

if you pseudocode what is required for this you have pretty much written the code....especially considering its to be written in vb.

if x = x then

y = y

else

if x = z then

y = y1

else

'etcetceyc

if you are doing a programming course OP and your posting like this.......you wont get far im sorry.

  • 0
  On 25/08/2013 at 00:48, Joe USer said:

Needs more GOTO's.

 

Challenge accepted!

 

REXX

/* REXX */
arg intAge .

/* There is no 'GOTO' in REXX. The statement to use is 'SIGNAL'					 */
/* This is the unconditional form of 'SIGNAL ON' that is used to catch exceptions	*/

if intage < 6 then do
		decticketprice = 0
		signal my_ass
	end
  
if intage <= 12 then do
		decticketprice = 3.5
		signal my_ass
	end
	
if intage <= 19 then do
		decticketprice = 4.5
		signal my_ass
	end
	
if intage > 62 then do
		decticketprice = 5.5
		signal my_ass
	end
	
decticketprice = 7.5

my_ass.

return decticketprice

Cobol

01 DECTICKETPRICE			PIC S9(5)V99 COMP-3.
01 INTAGE					PIC 9(3) COMP-3.

SOME-BOLLOCKS-CODE SECTION.

	IF INTAGE < 6
		MOVE ZERO TO DECTICKETPRICE
		GO TO MY-ASS
	END-IF.
	
	IF INTAGE <= 12
		MOVE 3.5  TO DECTICKETPRICE
		GO TO MY-ASS
	END-IF.
	
	IF INTAGE <= 19
		MOVE 4.5 TO DECTICKETPRICE	
		GO TO MY-ASS
	END-IF.
	
	
	IF INTAGE > 62 
		MOVE 5.5 TO DECTICKETPRICE
		GO TO MY-ASS
	END-IF.

	MOVE 7.5 TO DECTICKETPRICE.

MY-ASS.
	EXIT.

Easytrieve Plus

DECTICKETPRICE				W	4 P 2
INTAGE						W	2 P

SOME-BOLLOCKS-CODE. PROC

	IF INTAGE LT 6
		DECTICKETPRICE = 0
		GO TO MY-ASS
	END-IF

	IF INTAGE LE 12
		DECTICKETPRICE = 3.5
		GO TO MY-ASS
	END-IF
	
	IF INTAGE LE 19
		DECTICKETPRICE = 4.5
		GO TO MY-ASS
	END-IF
	
	IF INTAGE GT 62
		DECTICKETPRICE = 5.5
		GO TO MY-ASS
	END-IF

	DECTICKETPRICE = 7.5

MY-ASS.

END-PROC
  • Like 2
  • 0

Challenge accepted (again)!

Echo off
set intAge=%1%
if %intAge% LSS  6 (
	SET decTicketPrice=0
	goto done
)
if %intAge% LEQ 12 (
	SET decTicketPrice=3.5
	goto done
)
if %intAge% LEQ 19 (
	SET decTicketPrice=4.5
	goto done
)
if %intAge% GTR 62 (
	SET decTicketPrice=5.5
	goto done
)
set decTicketPrice=7.5

:done
Echo Ticket price is %decTicketPrice%
  • Like 2
  • 0
  On 24/08/2013 at 03:17, soccerstar206 said:

Write an If..ElseIf  statement (or Select Case if you prefer) given the following:

 

decTicketPrice                    ?ticket price

intAge                                  ?age of customer   

 

If customer's age is less than 6, ticket price is Free

 

If customer's age is 6 to 12, ticket price is $3.50

 

If customer's age is 13 to 19, ticket price is $4.50

 

If customer's age is over 62, ticket price is $5.50

 

Otherwise, ticket price is $7.50

All values of age were covered in the criteria; so no need for any 'else' statements.

 

But if you insist:

 

float decTicketPrice = 7.50;   // default ticket price

if (intAge < 6) decTicketPrice = 0.00 // under 6 are free

     else decTicketPrice = 3.50; // 6 and over base price is 3.50

 

/* The above statement just screwed up the teacher's requirement */

/* of an 'otherwise' ticket price since the customer is either under 6 */

/* or 6 or above. Dumb teacher giving dumb assignment fails.         */

 

if (intAge > 12) decTicketPrice += 1.00; // over 12 adds a dollar

if (intAge > 62) decTicketPrice += 1.00; // over 62 adds another dollar

  • 0
  On 29/08/2013 at 21:56, abecedarian paradoxious said:

All values of age are covered; no need for any 'else' statements.

 

float decTicketPrice = 0.00;

if (intAge >= 6) decTicketPrice += 3.50;

if (intAge >= 12) decTicketPrice += 1.00;

if (intAge >= 62) decTicketPrice += 1.00;

VB doesn't use semicolons to end a line ;)

  • 0
  On 29/08/2013 at 21:56, abecedarian paradoxious said:

All values of age are covered; no need for any 'else' statements.

 

float decTicketPrice = 0.00;

if (intAge >= 6) decTicketPrice += 3.50;

if (intAge >= 12) decTicketPrice += 1.00;

if (intAge >= 62) decTicketPrice += 1.00;

 

Doesn't cover the $7.50 cost if they are between 19 and 62.

  • 0
  On 29/08/2013 at 21:59, Lord Method Man said:

Doesn't cover the $7.50 cost if they are between 19 and 62.

Okay.

unsigned int intAge

// should be unsigned because negative ages aren't possible

// char is also permissible since people aren't likely to be > 255 years old

 

float decTicketPrice = 7.50   // default ticket price

 

if (intAge < 6) decTicketPrice = 0.00 // under 6 and you're in for free!

if (intAge > 5) and (intAge < 13) decTicketPrice += -4.00 // nice discount.

if (intAge > 12) and (intAge < 20) decTicketPrice += -3.00 // decent discount

if (intAge > 62) decTicketPrice += -2.00 // why the hate for senior citizens?

 

 

Still, no real reason for "else" conditions.

Start with the default and go.

  • 0
  On 29/08/2013 at 22:25, abecedarian paradoxious said:

Okay.

 

float decTicketPrice = 7.50

if (intAge <6 ) decTicketPrice = 0.00

if (intAge >5 ) and (intAge < 13) decTicketPrice += -4.00

if (intAge > 12) and (intAge <20) decTicketPrice += -3.00

if (intAge > 62) decTicketPrice += -2.00

 

 

Still, no real reason for "else" conditionals.

The reason is the assignment called for it.

 

Assignments are rarely designed to be the most efficient, but rather to teach a concept.

 

Not that it matters, the OP is clueless and wanted a handout.  And got it.

  • 0
  On 29/08/2013 at 22:31, adrynalyne said:

The reason is the assignment called for it.

 

Assignments are rarely designed to be the most efficient, but rather to teach a concept.

 

Not that it matters, the OP is clueless and wanted a handout.  And got it.

True, I suppose.

I always received 'extra credit' for thinking beyond the assignment though.

  • 0
  On 29/08/2013 at 22:40, abecedarian paradoxious said:

True, I suppose.

I always received 'extra credit' for thinking beyond the assignment though.

Heh, where I went, the instructors weren't allowed to give you extra credit.

This topic is now closed to further replies.
  • Posts

    • Shotcut 25.07 by Razvan Serea Shotcut is a free, open source, cross-platform video editor for Windows, Mac and Linux. Major features include support for a wide range of formats; no import required meaning native timeline editing; Blackmagic Design support for input and preview monitoring; and resolution support to 4k. Editing Features Trimming on source clip player or timeline with ripple option Append, insert, overwrite, lift, and ripple delete editing on the timeline 3-point editing Hide, mute, and lock track controls Multitrack timeline with thumbnails and waveforms Unlimited undo and redo for playlist edits including a history view Create, play, edit, save, load, encode, and stream MLT XML projects (with auto-save) Save and load trimmed clip as MLT XML file Load and play complex MLT XML file as a clip Drag-n-drop files from file manager Scrubbing and transport control Video Effects Video compositing across video tracks HTML5 (sans audio and video) as video source and filters 3-way (shadows, mids, highlights) color wheels for color correction and grading Eye dropper tool to pick neutral color for white balancing Deinterlacing Auto-rotate Fade in/out audio and fade video from and to black with easy-to-use fader controls on timeline Video wipe transitions: bar, barn door, box, clock (radial), diagonal, iris, matrix, and custom gradient image Track compositing/blending modes: Over, Add, Saturate, Multiply, Screen, Overlay, Darken, Dodge, Burn, Hard Light, Soft Light, Difference, Exclusion, HSL Hue, HSL Saturation, HSL Color, HSL Luminosity. Video Filters: Alpha Channel: Adjust, Alpha Channel: View, Blur, Brightness, Chroma Key: Advanced, Chroma Key: Simple, Contrast, Color Grading, Crop, Diffusion, Glow, Invert Colors, Key Spill: Advanced, Key Spill: Simple, Mirror, Old Film: Dust, Old Film: Grain, Old Film: Projector, Old Film: Scratches, Old Film: Technocolor, Opacity, Rotate, Rutt-Etra-Izer, Saturation, Sepia Tone, Sharpen, Size and Position, Stabilize, Text, Vignette, Wave, White Balance Speed effect for audio/video clips Hardware Support Blackmagic Design SDI and HDMI for input and preview monitoring Leap Motion for jog/shuttle control Webcam capture Audio capture to system audio card Capture (record) SDI, HDMI, webcam (V4L2), JACK audio, PulseAudio, IP stream, X11 screen, and Windows DirectShow devices Multi-core parallel image processing (when not using GPU and frame-dropping is disabled) DeckLink SDI keyer output OpenGL GPU-based image processing with 16-bit floating point linear per color component ShotCut 25.07 changelog: Added a Whisper.cpp (GGML) model downloader to the Speech to Text dialog. A model is no longer included in the download and installation reducing their sizes. Improved the System theme to follow the operating system palette on Windows (darker and more contrast), and improved its appearance on macOS dark mode. Added Settings > Theme > System Fusion that combines the operating system palette with the monochrome, symbolic icons of the Fusion themes. Added an Outline video filter that uses the input alpha channel--useful with rich text or assets with a transparent background. This means that, like Drop Shadow, it will not work as expected when used after a text filter on a video or image clip. Rather, you must use a text clip (transparent color generator with text filter) on an upper track. Other New Features Added the ability to drag the waveform peak line to adjust audio gain. Added Settings > Timeline > Adjust Clip Gain/Volume to turn off the above. Added rolling an edit/trim to Timeline: Hold Ctrl (command on macOS) while trimming to simultaneously trim the neighbor clip. Added a Soft Focus filter set. Added Audio/Video duration to the Slideshow Generator dialog, defaults to 4 hours. This facilitates using Slideshow Generator to make transitions between everything when including both video and images. (It still respects the source duration and in & out points; duration here is a maximum.) Surround Sound Mixing Improvements Added fader and surround balance to the Balance audio filter if channels > 2. Added Channels toggle buttons to many audio filters: Band Pass Compressor Delay Downmix Equalizer: 3-Band Equalizer: 15-Band Equalizer: Parametric Expander Gain/Volume High Pass Low Pass Limiter Mute Noise Gate Notch Added support for 4 channels in the Copy Channel audio filter. For example, now you can: Copy stereo music to the rear channels and use the fader in the Balance filter to reduce its volume, Downmix spoken word into the center channel and apply a Band Pass filter to it, and Route music or sound effects to the low-frequency channels and apply a Low Pass filter to it. Other Improvements Changed the default Export > Audio > Rate control to Average Bitrate for AAC, Opus, and MP3. Added the ability to add/use multiple Mask: Apply filters. Added support for Scrub While Dragging to trimming on the timeline. Added hold Shift to ripple-trim when Ripple is turned off. Added French (Canadian) and Lithuanian translations. Fixes Fixed Mask: Apply with multiple Mask: Simple Shape (broke in v25.05) Fixed exporting projects containing only Generator clips on Windows (broke in v25.05). Fixed converting 10-bit full to limited range (broke in v25.01). Fixed dropdown menus using Settings > Theme > System on Windows. Fixed Balance and Pan audio muted channels if audio channels > 2. Fixed Export > Use hardware encoder fails with H.264 on macOS 15. Fixed Properties > Convert or Reverse for iPhone 16 Pro videos with Ambisonic audio. Fixed a single frame fade out filter would either mute or make black. Fixed repairing a project (e.g. broken file links) with proxy turned on. Fixed doing Freeze Frame on the first frame of a clip. Download: ShotCut 25.07 | Portable | ARM64 ~200.0 MB (Open Source) View: Shotcut Home Page | Other Operating Systems | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Win8 still takes the crown though in terms of worst Microsoft OS which all boiled down to it's horrible interface upon release as it was actually difficult to do even basic stuff. I remember trying it in a VM early on and it was a chore doing the basics we have had for ages and I quickly dumped that and never bothered with it again. in fact, prior to Win11 it was the only OS from Microsoft I have never used/had on a real machine and I have been using windows from Win v3.11 in mid-1990's through Windows 10. basically Win v3.11, 95, 98, Me, 2k, XP, 7, Vista, 10. but putting Windows 8 aside, I would probably place Win11 next in line (lets start from WinXP to date since that's basically when Windows got good and PC's pretty much went mainstream), but at least Win11 is not in the 'horrible' category as at least it's basic interface is normal. but if I ignore the interface, Win11 is a strong candidate, not only for telemetry and the like, but forced "requirements" which make people jump through hoops we should not have to all in the name of "better security", which personally I think is not enough of a boost to justify the forced "requirements". but one area you can tell Linux is faster is installing updates and, as a bonus, we generally don't need to reboot (short of like Kernel updates but those I am in no rush as my longest every main PC system uptime without a reboot was Aug 2023 until Jan 2025). but yeah, I suspect all of the background junk Windows has running does slow things a bit. p.s. speaking of that 'CachyOS', I used one of their custom Proton's (on Lutris) to get NTSync recently as while I usually use the more typical 'GE-Proton10-10' (this and '10-9' have NTSync support which was added recently. but 10-9 you have to manually enable where as 10-10 is automatic if it's available in the kernel to the system), I have one game which does not play back in-game videos with the Proton 10 series (you can hear audio but it's basically a black screen) but works in the 9 series and 'CachyOS' had a build from Jan 2025 that has NTSync, so I used that and it worked. I had to use 'PROTON_USE_NTSYNC=1' though since it's not enabled by default (along with 'sudo modprobe ntsync', or setup a udev rule etc if you want it to work in reboots without needing to do that command). one can see NTSync is working through MangoHud if you setup 'winesync' (just add that entry to "~/.config/MangoHud/MangoHud.conf") in the configuration file for ManngoHud or if you want to directly see it in proton log I did 'PROTON_LOG=1', which then creates a log in the Home folder which, at least on GE-Proton10-10, creates 'steam-default.log' and in that shows "wineserver: NTSync up and running!" where as if you don't it will generally show "fsync: up and running."
    • Riverdale... in space? Hope not.
    • Then why didn't Apple upstream their feature?
    • Unix is in fact not open source.
  • Recent Achievements

    • Week One Done
      Lokmat Rajasthan earned a badge
      Week One Done
    • One Month Later
      TheRingmaster earned a badge
      One Month Later
    • First Post
      smileyhead earned a badge
      First Post
    • One Month Later
      K V earned a badge
      One Month Later
    • Week One Done
      K V earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      639
    2. 2
      ATLien_0
      241
    3. 3
      Xenon
      177
    4. 4
      neufuse
      155
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!