Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
BrianRx
Jul 21, 2007

raminasi posted:

C# is a great choice for this and the .NET thread would be happy to help with your tutorials.

LongSack posted:

Also, check out IAmTimCorey on YouTube. He has many C# related videos, and is (IMO) a pretty good teacher.

Thanks! I appreciate the resources.

Adbot
ADBOT LOVES YOU

Sab669
Sep 24, 2009

Is there a Salesforce thread? If so I can't find it and I recently started a new job with a lot of SF dev, and to quote my boss it's the blind leading the blind with this stuff :)

alexandriao
Jul 20, 2019


So I have a layout in a Python project that looks somewhat like this:

code:
lexapi/__init__.py
lexapi/lexapi.py
lexapi/lextypes.py
Inside the files are something like this:

code:
===== __init__.py ====
from .lexapi import LexAPI

===== lexapi.py ====
(...)
from lexapi import lextypes

class LexAPI():
    (...)

===== lextypes.py =====

(classes ...)

Everything works fine because I can summon "lexapi" from a test file outside of the lexapi directory, and lexapi.py finds the classes in lextypes.py just fine.

However when I try this with my recent project, with the exact same file layout:

code:
moreawful/__init__.py
moreawful/moreawful.py
moreawful/saexcept.py
With the exact same import structure:

code:
===== __init__.py ====
from .moreawful import SomethingAwfulAPI

===== moreawful.py ====
(...)
from moreawful import saexcept

class SomethingAwfulAPI():
    (...)

===== saexcept.py ====
class SAError(Exception):
      (...)
It gives me

code:
Traceback (most recent call last):
  File "live.py", line 1, in <module>
    import moreawful
  File "/home/alx/h/moreawful/moreawful/__init__.py", line 1, in <module>
    from .moreawful import SomethingAwfulAPI
  File "/home/alx/h/moreawful/moreawful/moreawful.py", line 5, in <module>
    from moreawful import saexcept
  File "/home/alx/h/moreawful/moreawful/saexcept.py", line 27, in <module>
    class SAInternalLoginError(SaError):
NameError: name 'SaError' is not defined
>>> 
Am I doing this wrong? Is there a "proper" way that I should be doing this? :ohdear:

alexandriao
Jul 20, 2019


lol nvm it was a case error.

hahahahaha I wasted a day on that :stonklol:

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

alexandriao posted:

lol nvm it was a case error.

hahahahaha I wasted a day on that :stonklol:

Been there.

So many times.

Woodsy Owl
Oct 27, 2004

Sab669 posted:

Is there a Salesforce thread? If so I can't find it and I recently started a new job with a lot of SF dev, and to quote my boss it's the blind leading the blind with this stuff :)

I don't think so but there are people with SF dev experience who lurk in this thread. Post away!

slightly lumpy
Jul 23, 2007
batter will be slightly lumpy
I'm thinking of buying The Linux Programming Interface for the second time because I lost my old copy. I was surprised to see that there are no new revisions; it's the same ol' thing from 2010. Any recommendations for either (1) buying a different, more modern book or (2) buying this old book 'cause it's still perfectly relevant. Curious to hear some opinions on this.

b0lt
Apr 29, 2005

slightly lumpy posted:

I'm thinking of buying The Linux Programming Interface for the second time because I lost my old copy. I was surprised to see that there are no new revisions; it's the same ol' thing from 2010. Any recommendations for either (1) buying a different, more modern book or (2) buying this old book 'cause it's still perfectly relevant. Curious to hear some opinions on this.

Very little has changed since then, and the most significant change since then (io_uring) is still undergoing rapid change (and also is irrelevant if you're not microoptimizing performance).

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Holy poo poo, the frustration of fighting with an AWS Lambda function all afternoon. And the short-lived rush of it FINALLY working just right.

I really need to sit down and learn Javascript cause my easter-egg troubleshooting technique is an exercise in frustration.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Hughmoris posted:

Holy poo poo, the frustration of fighting with an AWS Lambda function all afternoon. And the short-lived rush of it FINALLY working just right.

I really need to sit down and learn Javascript cause my easter-egg troubleshooting technique is an exercise in frustration.

I use the python runtime environments but man do I feel you. Using the AWS SAM so I can run in a lambda-like environ locally with the bonus of being able to use a terminal in the currently-running environ helped me solve problems MASSIVELY faster.

Basically I make a prototype in a jupyter notebook then move it to my AWS SAM environment. Run it with a try/except encapsulating it and the except is a 900s sleep. This gives me the remaining time to access it via the CLI and see what's not where I thought it'd be or whatever.

I presently have AWS Lambda functions that webscrape behind logins with headless Chrome and edit movies with ffmpeg (moviepy). This means lot of binaries and AM2 Linux for Lambda sure doesnt seem to have much installed library wise.

CarForumPoster fucked around with this message at 04:27 on Sep 18, 2021

slightly lumpy
Jul 23, 2007
batter will be slightly lumpy

b0lt posted:

Very little has changed since then, and the most significant change since then (io_uring) is still undergoing rapid change (and also is irrelevant if you're not microoptimizing performance).

Thanks, I appreciate that!

Edit: Anyone know of a CoC reading list laying around somewhere? I'm trying to read some especially high quality books during what will be a lot of time away from work. So far I'm internalizing Kleppmann and I'm thinking about reviewing parts of this Linux book. It's just that know there are many more gems out there that I'm not aware of.

slightly lumpy fucked around with this message at 09:43 on Sep 18, 2021

b0lt
Apr 29, 2005

slightly lumpy posted:

Edit: Anyone know of a CoC reading list laying around somewhere? I'm trying to read some especially high quality books during what will be a lot of time away from work. So far I'm internalizing Kleppmann and I'm thinking about reviewing parts of this Linux book. It's just that know there are many more gems out there that I'm not aware of.

The LWN guest articles have some excellent content. Especially good are the multi-part ones that go in depth about whatever they're written about : search for "part" to find them.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

slightly lumpy posted:

Thanks, I appreciate that!

Edit: Anyone know of a CoC reading list laying around somewhere? I'm trying to read some especially high quality books during what will be a lot of time away from work. So far I'm internalizing Kleppmann and I'm thinking about reviewing parts of this Linux book. It's just that know there are many more gems out there that I'm not aware of.

https://www.dataorienteddesign.com/dodmain/ is good

If you're looking for something more fun rather than terribly useful, pragmatic bookshelf has a few tutorial based project led books. Mazes for programmers and the ray testing challenge were both good.

Dawncloack
Nov 26, 2007
ECKS DEE!
Nap Ghost
I am starting to learn and practice parallelism in python, and one little project I had was to reimplement rsync (so, a backup function that checks whether something is already there and if it's the latest version then just doesn't copy).

I know that an IO bound problem is better handled with multithreading and a CPU bound problem with multiprocessing.
But what about a memory bound problem, like what I am trying to do? Am I right in thinking that the Von Neumann choke means that nothing will really help?

I have so far implemented it with multiple processing and I found through experimentation that when I am making a fresh backup into an empty memory, both the multiprocessing and sequential version take the same amount of time. But if the backup is already there, the multiprocessing version is faster. I imagine because the memory bus is not overloaded by copying all the stuff. However, if anyone could point me in the direction of some insightful reading I'd really appreciate.

Thanks in advance!

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Dawncloack posted:

I am starting to learn and practice parallelism in python, and one little project I had was to reimplement rsync (so, a backup function that checks whether something is already there and if it's the latest version then just doesn't copy).

I know that an IO bound problem is better handled with multithreading and a CPU bound problem with multiprocessing.
But what about a memory bound problem, like what I am trying to do? Am I right in thinking that the Von Neumann choke means that nothing will really help?

I have so far implemented it with multiple processing and I found through experimentation that when I am making a fresh backup into an empty memory, both the multiprocessing and sequential version take the same amount of time. But if the backup is already there, the multiprocessing version is faster. I imagine because the memory bus is not overloaded by copying all the stuff. However, if anyone could point me in the direction of some insightful reading I'd really appreciate.

Thanks in advance!

Python is a pretty bad choice for parallel computing. But without knowing more about the problem it's hard to say where it's blowing up without profiling data.

If you have many files not a single file, you'd be potentially bottlenecked on opening all of them. You'd also run into the file handle limit at some point.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Are you doing a memory-to-memory rsync or something? File copying, as in taking bits from one sector on the disk and storing a duplicate of those bits in a different sector on potentially a different disk, is almost always going to be I/O bound.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Regex wizards, I call upon thee.

I have a text file full of questions/choices. My ultimate goal is to split it up and spit it in to a CSV using Python 3.8. I'm having trouble creating a capture group that will capture a multiline chunk.

https://regex101.com/r/zoprFw/1

In that example, I'd ideally have two capture groups. One for each question with accompanying choices. Any guidance is appreciated!

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Hughmoris posted:

Regex wizards, I call upon thee.

I have a text file full of questions/choices. My ultimate goal is to split it up and spit it in to a CSV using Python 3.8. I'm having trouble creating a capture group that will capture a multiline chunk.

https://regex101.com/r/zoprFw/1

In that example, I'd ideally have two capture groups. One for each question with accompanying choices. Any guidance is appreciated!

code:
"(^  \d.*\n((?!  \d).*\n?)+)+"gm

Assuming the whitespace before the questions is consistent. Otherwise it's harder.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

ShoulderDaemon posted:

code:
"(^  \d.*\n((?!  \d).*\n?)+)+"gm
Assuming the whitespace before the questions is consistent. Otherwise it's harder.

You are a scholar, and a saint. I slightly tweaked what you provided because it didn't seem to work with more than 2 questions, and I have 1000 or so in the text file.

I'll give it a go tomorrow in the python script but here is where I landed:
code:
 (^  \d.*\n((?!  \d).*\n?)+$)

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm curious, how do you all take notes/reminders when building personal projects?

I'm working on learning some core AWS services, all of which are new to me. So I'm reading documentation on how to create and connect to an AWS RDS database, which then takes a little trial and error. Then how to create MySQL tables. Then the necessary Python modules to connect to said database, and the proper syntax to insert values etc...

There is no way I'll remember all the "gotchas" if I try to recreate this next month. I'm thinking either I create a OneNote, or maybe leverage GitHub some how, and curious how others go about it.

CarForumPoster
Jun 26, 2013

⚡POWER⚡

Hughmoris posted:

I'm curious, how do you all take notes/reminders when building personal projects?

I'm working on learning some core AWS services, all of which are new to me. So I'm reading documentation on how to create and connect to an AWS RDS database, which then takes a little trial and error. Then how to create MySQL tables. Then the necessary Python modules to connect to said database, and the proper syntax to insert values etc...

There is no way I'll remember all the "gotchas" if I try to recreate this next month. I'm thinking either I create a OneNote, or maybe leverage GitHub some how, and curious how others go about it.

Depends but simple ones I put in the readme.

Sab669
Sep 24, 2009

Woodsy Owl posted:

I don't think so but there are people with SF dev experience who lurk in this thread. Post away!

I figured out whatever my issue was on my own :v: But having a new, dumb issue this morning. All of my SF plugins for VSCode throw a "unsupported Java version detected" error, which sounds quite straight forward. But I downloaded the latest version of both the JRE and JDK and rebooted multiple times. Environment variables are all set up



(JDK 17 is from a fresh attempt this morning)

Any idea what else I'm missing? All I can find on google is just "download jre/jdk and reboot" basically. Which I've tried of course.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Hughmoris posted:

I'm curious, how do you all take notes/reminders when building personal projects?

I'm working on learning some core AWS services, all of which are new to me. So I'm reading documentation on how to create and connect to an AWS RDS database, which then takes a little trial and error. Then how to create MySQL tables. Then the necessary Python modules to connect to said database, and the proper syntax to insert values etc...

There is no way I'll remember all the "gotchas" if I try to recreate this next month. I'm thinking either I create a OneNote, or maybe leverage GitHub some how, and curious how others go about it.

Physical notebooks. Or personal wiki.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Hughmoris posted:

I'm curious, how do you all take notes/reminders when building personal projects?

I'm working on learning some core AWS services, all of which are new to me. So I'm reading documentation on how to create and connect to an AWS RDS database, which then takes a little trial and error. Then how to create MySQL tables. Then the necessary Python modules to connect to said database, and the proper syntax to insert values etc...

There is no way I'll remember all the "gotchas" if I try to recreate this next month. I'm thinking either I create a OneNote, or maybe leverage GitHub some how, and curious how others go about it.

In general I don't and then I regret it later. But if I do go to the trouble it's generally readme files included in the repo because why separate the two things?

necrotic
Aug 2, 2005
I owe my brother big time for this!

Sab669 posted:

I figured out whatever my issue was on my own :v: But having a new, dumb issue this morning. All of my SF plugins for VSCode throw a "unsupported Java version detected" error, which sounds quite straight forward. But I downloaded the latest version of both the JRE and JDK and rebooted multiple times. Environment variables are all set up



(JDK 17 is from a fresh attempt this morning)

Any idea what else I'm missing? All I can find on google is just "download jre/jdk and reboot" basically. Which I've tried of course.

JRE 1.8 is Java 8… you may not have downloaded the correct JRE.

Sab669
Sep 24, 2009

:shrug: That's what I've got after downloading from here; https://www.java.com/en/download/

But I figured it out. Somehow the "Java: Home" path setting within VSCode got wiped out from when I first set up the Salesforce extensions a few weeks ago. So simply reassigning that value to the jdk-17 folder fixed it.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Sab669 posted:

:shrug: That's what I've got after downloading from here; https://www.java.com/en/download/

But I figured it out. Somehow the "Java: Home" path setting within VSCode got wiped out from when I first set up the Salesforce extensions a few weeks ago. So simply reassigning that value to the jdk-17 folder fixed it.

Yeah, its wild that java.com still only serves up 1.8! You found the right fix, though.

Elephant Ambush
Nov 13, 2012

...We sholde spenden more time together. What sayest thou?
Nap Ghost
Is there a thread where I could go to ask about how to set up an online store?

OtspIII
Sep 22, 2002

Github recently changed its security procedures, and I'm hoping I'm misunderstanding something. Is there an easier way to log in and push stuff than to generate a .ssh file in terminal and fuss around configuring stuff everywhere? Am I just missing some sort of "just log in with a user account and password" method that still exists?

For context, I'm teaching a bunch of lower undergrad game dev students how to use git and getting their environments set up has been an utter shitshow in a way that it didn't used to be. There has to be a better way than getting a bunch of students who have never even heard of the terminal before to go about generating and setting up key files between multiple services and programs, right?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You just need to generate a Personal Authentication Token from the web UI, and then it's the same as before except you use that instead of your account password when interacting with the CLI.

ToxicFrog
Apr 26, 2008


Hughmoris posted:

I'm curious, how do you all take notes/reminders when building personal projects?

I'm working on learning some core AWS services, all of which are new to me. So I'm reading documentation on how to create and connect to an AWS RDS database, which then takes a little trial and error. Then how to create MySQL tables. Then the necessary Python modules to connect to said database, and the proper syntax to insert values etc...

There is no way I'll remember all the "gotchas" if I try to recreate this next month. I'm thinking either I create a OneNote, or maybe leverage GitHub some how, and curious how others go about it.

Stuff tied to a specific bit of code: comments or docstrings. I tend to have a lot of TODOs in my code while I'm working on something and if I ever feel like the next step is non-obvious `git grep TODO` will often have me going "oh right, I need to do $thing".

More general architecture/design/speculation stuff: NOTES file in the project root, plaintext. I'll often use this as a scratch pad/rubber duck when designing stuff (sometimes accompanied by a pad of paper for weird diagrams that are hard to represent in text). Ideally by the time the project is finished the NOTES file is empty -- everything in it has either been discarded as a dead end, realized in code, or cleaned up and moved into the README.

Gothmog1065
May 14, 2009
sed help!

For those who actually use this data, this is going to be run on HL7 data, so that may help. Quick rundown, it's a pipe-delimited message standard. \r (shown as a ^M control character in the data itself) breaks lines. A sample string that can be seen:

MSH|^~\&|string|string||||||^MPID|string|string|string|data1^data2^data3|^^^|other^strings^here^^^||^MPV1|<etc>

My objective here is twofold.

1 - Remove all trailing carats in the fields (anything between pipes). eg - other^string^here^^^ will become other^string^here -- this includes "blank" fields: |^^^| will become ||.

2 - Remove all trailing pipes (|) at the end of segments (basically each line, between control characters): MSH|^~\&|string|string||||||^M will become MSH|^~\&|string|string^M

Ultimately the ending string should look like this:

MSH|^~\&|string|string^MPID|string|string|string|data1^data2^data3||other^strings^here^MPV1|<etc>

Current access to sh (bash and ksh93 mostly), so I could probably use awk or sed. I could have this complied into a C or C++ program, but not too familiar with that, and for some ungodly reason they installed RHEL without Python, which I will resolve if that will make things easier. If this does get put into a script, this could potentially be run on large amounts of data, so speed will be a factor.

My current thought is sed, and my regex in sed isn't that great.

The carats are easy enough:
code:
sed 's/\(\S\)^\+|/\1|/g
Same with the trailing pipes (after the empty ^'s are removed -- also can't bold in code text, pretend the ^Ms are ^M):
code:
sed 's/|\+^M/\^M/g'
So basically, is this the best way to do this? sed the files in a simple script, or is there a better way in (k)sh or python or something else to make sure it runs as fast as possible?

e: fixed some issues and new 'problem'.

Here's the kink I found that causes major problems. There are also 'repeating fields' delimited by a ~ that need to be 'fixed':
|abc^^~bcd^^~def^^| needs to be |abc~bcd~def| However, if I do the basic modification from above: sed '/s/\(\S\)^\+~/\1~/g, it works, EXCEPT it also replaces the MSH|^~ with MSH|~ which SHOULD NOT happen. I could go and sed back in the ^ (sed 's/MSH|~/MSH|^~/), but that seems unnecessary.

e2:

I've worked my sed statements down a bit, and have shaved 14 seconds off the time in a bash script:

code:
while read -r line; do
  echo ${line} | sed 's/\(\S\)^\+\(|\|~\)/\1\2/g' | sed 's/\^MSH|~/MSH|^~/' | sed 's/|\+^M/\^M/g' > ${newFile}
done < ${input}
I might just cat the entire file and sed that, we'll see if that makes it faster. Would still be nice to be faster, but can only do so much without putting it in /dev/shm.

Gothmog1065 fucked around with this message at 16:50 on Oct 1, 2021

Toast Museum
Dec 3, 2005

30% Iron Chef

I don't have a head-on answer to your regex questions, but since languages like C++ and Python are on the table, maybe you don't have to reinvent the wheel. It looks like there are multiple HL7 parser libraries out there; any chance one of them meets your needs?

ToxicFrog
Apr 26, 2008


Gothmog1065 posted:

My objective here is twofold.

1 - Remove all trailing carats in the fields (anything between pipes). eg - other^string^here^^^ will become other^string^here -- this includes "blank" fields: |^^^| will become ||.

2 - Remove all trailing pipes (|) at the end of segments (basically each line, between control characters): MSH|^~\&|string|string||||||^M will become MSH|^~\&|string|string^M

e2:

I've worked my sed statements down a bit, and have shaved 14 seconds off the time in a bash script:

code:
while read -r line; do
  echo ${line} | sed 's/\(\S\)^\+\(|\|~\)/\1\2/g' | sed 's/\^MSH|~/MSH|^~/' | sed 's/|\+^M/\^M/g' > ${newFile}
done < ${input}
I might just cat the entire file and sed that, we'll see if that makes it faster. Would still be nice to be faster, but can only do so much without putting it in /dev/shm.

Doing the entire file in one sed call will be faster, yeah. Whether it's noticeably faster depends on how big your files are. Also, your code as written there will process the entire input file, but will only save the last line to the output file -- each time around the loop it erases the previous contents of newFile.

I'd also use sed -E (which turns on EREs rather than BREs, saving you a lot of backslashes, although not as much here as it usually does due to the profusion of literal | and ^ in the patterns):

code:
cat "${input}" | mac2unix | sed -E '
  s,\^+([|~]),\1,g
  s,\|+$,,
  s,^MSH\|~,MSH|^~,
' | unix2mac > "${newFile}"
If you don't have mac2unix/unix2mac available, you can replace them with tr '\r' '\n' and tr '\n' '\r' respectively.

Gothmog1065
May 14, 2009

ToxicFrog posted:

Doing the entire file in one sed call will be faster, yeah. Whether it's noticeably faster depends on how big your files are. Also, your code as written there will process the entire input file, but will only save the last line to the output file -- each time around the loop it erases the previous contents of newFile.

I'd also use sed -E (which turns on EREs rather than BREs, saving you a lot of backslashes, although not as much here as it usually does due to the profusion of literal | and ^ in the patterns):

code:
cat "${input}" | mac2unix | sed -E '
  s,\^+([|~]),\1,g
  s,\|+$,,
  s,^MSH\|~,MSH|^~,
' | unix2mac > "${newFile}"
If you don't have mac2unix/unix2mac available, you can replace them with tr '\r' '\n' and tr '\n' '\r' respectively.

Thanks. I actually did a run on the entire file at once, and noticeably is not the word. It went from 90 seconds to 3 seconds. I am going to re-run monday to make sure I didn't gently caress up which files I was looking at, but when I did the entire file it worked, except it also removed all extra whitespace (double spaces after periods, multiple spaces after colons for whatever reason), which creates other differences I don't want.

I'm not sure if it's the way the files write out the HL7 data, but if done the same way, they all have the carriage return (^M or \r) between segments, but have the CRLF at the end (\r\n or ^M^J). Just looking at the data file in vi (not using -b), the CR shows as ^M, but writing the code, we actually use \r to do any replacement functions with it. So the CR shows up between segments, but nowhere else.

Also, the difference between vim substituion and sed may be throwing me off on s/|^M/\^M/g -- I know in vim you have to protect that control character or it will expand it and actually put everything on different lines vs inserting the control character back in.

Gotta love learning as you go.

The last oddity may just be sed versioning, but when doing something like the above control character replacement:

Selklubber
Jul 11, 2010
so i have to manage a project to program a program with some people. I can choose between gitlab and jira for planning features/functionality, bugtracking and stuff. We're gonna use gitlab for source control. is it best to use gitlab for ALL project control stuff, or use the jira integration and have the gitlab project connected to jira?

I've worked with gitlab before and it was ok, never tried jira project before. I just want some place where i can create point of stuff we have to work on, what we have to plan before starting programming and stuff like that.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Jira sucks, use Gitlab and assign your issues to milestones to go with release tags

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club
Hey, you guys know Coral? It's a hip limited programing language that's kindasorta like Python but very limited and used for teaching. I've got a simple assignment but one small part of it is wrecking me.

The assignment reads:

Primary U.S. interstate highways are numbered 1-99. Odd numbers (like the 5 or 95) go north/south, and evens (like the 10 or 90) go east/west. Auxiliary highways are numbered 100-999, and service the primary highway indicated by the rightmost two digits. Thus, the 405 services the 5, and the 290 services the 90.

Given a highway number, indicate whether it is a primary or auxiliary highway. If auxiliary, indicate what primary highway it serves. Also indicate if the (primary) highway runs north/south or east/west.


and my code is:

code:
integer primaryNumber
integer aux
integer northsouth
integer valid

highwayNumber = Get next input

if (highwayNumber > 99) and (highwayNumber < 1000)
   aux = 1
else
   aux = 0

primaryNumber = highwayNumber %100

if highwayNumber %2 == 0
   northsouth = 0
else
   northsouth = 1

if (highwayNumber <= 0 or highwayNumber >999)
   valid = 0
else
   valid = 1

if valid == 0
   Put highwayNumber to output
   Put " is not a valid interstate number." to output
else
   Put "The " to output
   Put highwayNumber to output
   Put " is " to output
if aux == 1
   Put "auxiliary, serving the " to output
   Put primaryNumber to output
   Put "," to output
   Put " going " to output
else
   Put "primary," to output
   Put " going " to output
if northsouth == 1
   Put "north/south." to output
else
   Put "east/west." to output
The problem is that, if the highway is invalid, it does give me the correct output, but then it proceeds to run the rest of the program, adding a bunch of nonsense. I feel like this is such a simple solution but I've gone through whole curriculum and I can't figure out what the proper solution is. I want the program to accept the output that the highway is invalid and then just ignore everything that comes after, as it doesn't apply, but I don't think adding if/else/elseif statements to every single line is the right way.

So I guess what I'm wanting is the last two if/else statements to fall under the previous if statement but I can't do that in Coral. It only allows for a single, uh, nesting? I forget what it's called. Clearly I'm new to this.

credburn fucked around with this message at 19:18 on Oct 12, 2021

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Try adding an extra layer of indentation to if aux == 1 and everything after it.

Adbot
ADBOT LOVES YOU

credburn
Jun 22, 2016
President, Founder of the Brent Spiner Fan Club

ultrafilter posted:

Try adding an extra layer of indentation to if aux == 1 and everything after it.

Right, so that's the thing about Coral as it only allows a single indentation layer. I do believe in any other language it would be as easy as that.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply