• 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

    • Then why didn't Apple upstream their feature?
    • Unix is in fact not open source.
    • Microsoft Weekly: a new Surface, big Windows 11 feature update, and more by Taras Buria Image: terski on Pixabay This week's news recap is here with big Windows 11 updates, more apps rejecting Windows Recall, browser updates, welcome pricing changes for Xbox games, a single Windows 11 preview build, and other stories. Quick links: Windows 10 and 11 Windows Insider Program Updates are available Reviews are in Gaming news Great deals to check Windows 11 and Windows 10 Here, we talk about everything happening around Microsoft's latest operating system in the Stable channel and preview builds: new features, removed features, controversies, bugs, interesting findings, and more. And, of course, you may find a word or two about older versions. July 2025 non-security updates for Windows 10 and 11 are here, and they bring a pretty hefty list of various changes and new features. Windows 10 received KB5062649, while Windows 11 versions 22H2 and 23H2 got KB5062663 with fixes for file systems, input, networking, printing, and more. The biggest changelog has Windows 11 version 24H2 and its KB5062660 update. It brings a handful of new AI-powered features, Settings improvements, a redesigned BSOD with Quick Machine Recovery, and a lot more. Speaking of AI-powered features, more and more companies turn their backs on Windows Recall, Windows 11's flagship AI thingy. Brave and AdGuard announced that they will block Windows Recall because the feature itself is unsettling, and Microsoft's privacy efforts are not enough. Microsoft is working on a new tool that can help you upgrade from your old computer to a new one. The app can transfer not only settings but also files. In a newly published support document, Microsoft explained how the recently discovered experience works. In this article, we take a closer look at what is coming soon. We also published a big article that explained everything you need to know about the end of Windows 10 support. If you are a Windows 10 user, check it out here to prepare for the inevitable. If your Windows 10 exodus strategy is to switch to Linux, you may find this app useful. It can transfer important data from Windows 10 to Linux. By the way, Windows 10 is not the only Windows version to lose support on October 14. Certain Windows 11 versions will also reach the end of life on that fateful day. Another useful guide that we published this week explains how to disable reserved storage to free some space on your computer. Finally, check out this article detailing Windows Sandbox, a highly underrated feature, and an overview of 10 Windows 10 features that promised a lot but failed to take off. Windows Insider Program Here is what Microsoft released for Windows Insiders this week: Builds Canary Channel Build 27909 Nothing major in this build. The update only adds a couple of fixes here and there. Dev Channel Nothing in the Dev Channel this week Beta Channel Nothing in the Beta Channel this week Release Preview Channel Nothing in the Release Preview this week Recent Windows 11 preview builds were found to contain a welcome audio feature that allows sharing audio to several devices. Just open Quick Settings, click Shared Audio, and select the devices you need. Microsoft has not announced it yet, so stay tuned for official details. Also, Microsoft wants to improve Windows 11 with a new system that detects performance slowdowns and sends diagnostic data to the company. This system is now available in the latest Windows 11 preview builds. For Phone Link users with Android smartphones, Microsoft released some useful updates. The Link to Windows app now has remote controls, allowing you to lock your PC, send files, or mirror your phone's screen. There is also a redesigned UI and a better onboarding experience. Finally, Microsoft is testing a redesigned news feed in Windows Widgets, with Copilot Discover taking over the classic MSN feed, and a new Copilot Appearance feature that adds non-verbal communication to Copilot, enhancing voice conversations with real-time visual expression. Updates are available This section covers software, firmware, and other notable updates (released and coming soon) delivering new features, security fixes, improvements, patches, and more from Microsoft and third parties. Microsoft has a new Surface in its device lineup. The Surface Laptop 7 with Intel's Core Ultra 200 Series processors is now available with optional 5G connectivity. Microsoft said in the announcement post that equipping a laptop with 5G was not just putting a modem inside. Microsoft had to carefully engineer a so-called "dynamic antenna system" that adapts to the environment and ensures the best reception by having six strategically placed antennas. A rather unfortunate event happened to SharePoint this week. Microsoft revealed details about hackers exploiting an unpatched SharePoint vulnerability, which even managed to breach the US nuclear weapons department, and quickly posted detailed guidance about it alongside much-needed fixes. Files, one of our favorite file managers for Windows 10 and 11, received a big preview update with a reworked address bar. The new Omnibar now combines the address bar and search bar, offering users a more intuitive experience alongside other improvements. Meta is making some significant changes to the WhatsApp client on Windows. The messenger is ditching UWP for a progressive web app, which is now available in beta in the Microsoft Store. Firefox received a big new feature update. Version 141.0 is now available with AI-powered tab groups, vertical tab improvements, WebGPU support, and other changes. Microsoft Edge, on the other hand, received some security fixes and contextual capabilities in the Business Chat work tab. Finally, check out a recap of all the new features that Microsoft added to Intune in July 2025, and a crucial data refresh feature for Excel, alongside a highly-requested PivotTable feature. Here are other updates and releases you may find interesting: Microsoft encourages Windows driver development in Rust for better security. Microsoft invests in European languages and culture to build smarter, more inclusive AI. UniGetUI received a massive update with bulk download options. Microsoft CEO finally addressed the recent layoff of 9,000 employees. Microsoft is planning a huge upgrade for Visual Studio. Microsoft Viva Insights boosts Copilot and learning with new reports. Windows 365 received a big RDP upgrade. Here are the latest drivers and firmware updates released this week: Intel 32.0.101.6972 non-WHQL with optimizations for Killing Floor 3, Valorant's Unreal Engine 5 upgrade, and Wuchang: Fallen Feathers. Nvidia 577.00 WHQL with Valorant UE5 upgrade support, WUCHANG: Fallen Feathers, and more Reviews are in Here is the hardware and software we reviewed this week Robbie Khan reviewed the GameSir G7 Pro, a fantastic Xbox-licensed controller with TMR sticks, excellent software, optical buttons, and premium materials. Steven Parker reviewed the OXS Storm A2, a wireless gaming headset with hybrid ANC. On the gaming side Learn about upcoming game releases, Xbox rumors, new hardware, software updates, freebies, deals, discounts, and more. This week, Microsoft announced some useful gaming updates. The company is now testing cross-device play history on Xbox consoles and PC, which should let players easily jump back into games that support features like Xbox Play Anywhere or Xbox Cloud Gaming, regardless of what platform they are using. Another useful and welcome update is about the future prices of Xbox games. Microsoft made a sudden U-turn and ditched the $80 price tag, which was supposed to arrive with the launch of The Outer Worlds 2. EA has finally announced the next Battlefield game that is coming soon. The first Battlefield 6 trailer shows off a major conflict breaking out across the world, with what looks to be a rogue mercenary group named Pax Armata attacking NATO and its allies. Nvidia announced new games for the GeForce NOW cloud streaming service. The latest additions include Abiotic Factor, WUCHANG: Fallen Feathers, Barony, He is Coming, SUPERVIVE, Wildgate, and more. Keep in mind that you have to own these games to play them using GeForce NOW. Deals and freebies This week's Weekend PC Game Deals is here with various discounts across multiple stores and a new freebie from the Epic Games Store. The latter is giving away Legion TD 2. Other gaming news includes the following: Ubisoft confirms Avatar: Frontiers of Pandora is getting a third-person mode and New Game+ Assassin's Creed Shadows is getting New Game+, level cap increase, and more ahead of DLC launch Valve is redesigning the Steam Store Menu and Search, wants user feedback Frostpunk 2 arrives to Xbox and PlayStation this September, hits Game Pass on day one Great deals to check Every week, we cover many deals on different hardware and software. The following discounts are still available, so check them out. You might find something you want or need. Acer Aspire C27 AIO Desktop - $739.99 | 13% off HP 15.6-inch laptop (model 15-fc0499nr) - $399.99 | 20% off CMF Watch 3 Pro Smart Watch - $79 | 20% off 2TB Crucial P310 NVMe SSD - $149.99 | 38% off 2TB Crucial T710 NVMe SSD - $229.99 | 36% off Samsung Galaxy Tab S10 FE Wi-Fi - $449.99 | 10% off Motorola Edge 2025 - $439.99 | 20% off This link will take you to other issues of the Microsoft Weekly series. You can also support Neowin by registering a free member account or subscribing for extra member benefits, along with an ad-free tier option.
    • A female Jem'Hadar makes no bloody sense whatsoever... They're a male only, genetically engineered, clone species...  Did the idiots making this not watch ANY of DS9, or bother to check a wiki, at ALL? This is going to be crap, isn't it?    
    • Internet Download Manager (IDM) 6.42 Build 42 by Razvan Serea Internet Download Manager (IDM) is a tool to increase download speeds by up to 5 times, resume and schedule downloads. Comprehensive error recovery and resume capability will restart broken or interrupted downloads due to lost connections, network problems, computer shutdowns, or unexpected power outages. IDM integrates seamlessly into Google Chrome, FireFox, Microsoft Edge, Opera, Safari, Internet Explorer, Maxthon and all other popular browsers to automatically handle your downloads. You can also drag and drop files, or use Internet Download Manager from command line. The program supports proxy servers, ftp and http protocols, firewalls, redirects, cookies, authorization, MP3 audio and video content processing. Changes in Internet Download Manager 6.42 Build 42: Updated Chrome extension to support Chrome manifest 3 Fixed bugs Download: Internet Download Manager 6.42 Build 42 | 11.7 MB (Shareware) Links: Internet Download Manager Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • 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
      176
    4. 4
      neufuse
      155
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!