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
JawnV6
Jul 4, 2004

So hot ...
edit: I'm XYing here

JawnV6 fucked around with this message at 21:43 on Feb 24, 2016

Adbot
ADBOT LOVES YOU

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
Stupid question: can someone explain enviornment variables to me? Are these just super mega global variables that anyone/anything can edit? I ask because I know in node there are sometimes process enviornment variables I have to set. And then reading up on some man pages for a particular linux command, a command can take input from an enviornment variable. So can I just have node change this enviornment variable and then run the command or are these scopes totally outside of each other?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
There is a group of environment variables for each process. When a process A spawns a new process B, B's environment starts with a copy of A's environment. A process can modify its own environment using the "setenv" and "getenv" library functions.

They're often used to pass configuration into programs, since they can be set by whatever spawns a process.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

Suspicious Dish posted:

There is a group of environment variables for each process. When a process A spawns a new process B, B's environment starts with a copy of A's environment. A process can modify its own environment using the "setenv" and "getenv" library functions.

They're often used to pass configuration into programs, since they can be set by whatever spawns a process.

OK so if I am using node to spawn a child process, because i am spawning that process using bash ultimately, whatever node env's are set won't really be passed to the spawned process, but bashes will instead correct?

JawnV6
Jul 4, 2004

So hot ...
How long would it take to set up a small test case with a brand new env variable that node sets and gets checked in the child?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Knifegrab posted:

OK so if I am using node to spawn a child process, because i am spawning that process using bash ultimately, whatever node env's are set won't really be passed to the spawned process, but bashes will instead correct?

So bash (process A) spawns node (process B), which spawns custom-thing (process C)?

When bash spawns node, bash's current environment gets copied and shoved in node.

When node spawns custom-thing, node's current environment gets copied and shoved in custom-thing.

bash's environment has no influence on custom-thing, except for variables that have been passed through node.

sarehu
Apr 20, 2007

(call/cc call/cc)

Knifegrab posted:

Stupid question: can someone explain enviornment variables to me?

You've got two parts: Part I: When processes are spawned, they get a list of environment variables -- the same as they do with command line arguments. Part II: When spawning other processes, you pass a list of environment variables down to the callee.

If "you" aren't explicitly passing environment variables in Part II, it's because your standard library is automatically pulling them out of a global variable and passing them for you. (That global variable originally got set from the environment that was passed into your process, and then perhaps got modified by you with some setenv function, if you did that sort of thing.)

Knifegrab posted:

OK so if I am using node to spawn a child process, because i am spawning that process using bash ultimately, whatever node env's are set won't really be passed to the spawned process, but bashes will instead correct?

Assuming you are using bash somehow instead of just spawning the sub-process directly, what happens here is that your program spawns a new instance of bash, passes it whatever environment variables it wants (typically, the ones it was passed). Then bash passes those along to its subprocess -- it doesn't know what the other bash process's environment variables were -- and maybe it might pass some extra environment variable to its sub-process, because it's bash, I don't know, you could look and see.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

sarehu posted:

You've got two parts: Part I: When processes are spawned, they get a list of environment variables -- the same as they do with command line arguments. Part II: When spawning other processes, you pass a list of environment variables down to the callee.

If "you" aren't explicitly passing environment variables in Part II, it's because your standard library is automatically pulling them out of a global variable and passing them for you. (That global variable originally got set from the environment that was passed into your process, and then perhaps got modified by you with some setenv function, if you did that sort of thing.)


Assuming you are using bash somehow instead of just spawning the sub-process directly, what happens here is that your program spawns a new instance of bash, passes it whatever environment variables it wants (typically, the ones it was passed). Then bash passes those along to its subprocess -- it doesn't know what the other bash process's environment variables were -- and maybe it might pass some extra environment variable to its sub-process, because it's bash, I don't know, you could look and see.

OK this makes more sense thank you for the clarification. OK so what if I have something like this:

I have a node server that is running express to handle multi-user webpage delivery. I have a process that can be kicked off by any number of users at any time. This process involves setting a node env variable, and then passing that env variable to bash which then spawns another child process to run. In the script that can be run by the user, I set the env variable (which will be different for each user) and then spawn the process.

Now because there is only one instance of node running (the express server) is it possible that a collision could occur due to the non-blocking behavior of the script I am running where:

-User A kicks off the script
-Node sets env variable for User A and kicks off a promise for the spawning of the child process (this is non-blocking)
-Before the child process is spawned User B then kicks off the script
-Still before the promise resolves, the env variable is now changed for User B
-The promise resolves, having used the env variable after it was set by user B.

In this instance will a collision have occured? Or will User A's script and User B's script have env variables only scoped to themselves so no collision can occur.

I am largely self-taught in most of my coding/learned on the job so I apologize if I am using some really dumb and bad terminology here. If I am being confusing let me know as well.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Anyone know where I can get a good list of RSS feeds to test a feed parser?

I found a list of 1000 feeds, but a lot of them were all generated by the same generators like wordpress and the like. I'd like a larger variety.

sarehu
Apr 20, 2007

(call/cc call/cc)

Knifegrab posted:

-User A kicks off the script
-Node sets env variable for User A and kicks off a promise for the spawning of the child process (this is non-blocking)
-Before the child process is spawned User B then kicks off the script
-Still before the promise resolves, the env variable is now changed for User B
-The promise resolves, having used the env variable after it was set by user B.

In this instance will a collision have occured? Or will User A's script and User B's script have env variables only scoped to themselves so no collision can occur.

It would be pretty bad (a) for an async API that depends on global variables to not make a copy or snapshot of them at the time it's called before doing anything, and (b) API design matters aside, for a process spawning API to not have made a syscall that has already passed the env itself, before returning.

So I think you're fine. I mean, the way you're doing it is generally icky, setting the global environment and then having that value sit there in the env for something later to pick it up -- it could leak the information from User A to other users, and such, and increases the general chance of bugs.

You could always look at the standard library (or whatever library) source code to examine its behavior in finer detail. Seriously. I found it to be a mess, but it was still just Javascript down to some level, you could probably see when and how it pulls the information from process.env.

Subyng
May 4, 2013
If I'm converting from a float to double in C or C++, there shouldn't be any reason why I would lose precision, right?

sarehu
Apr 20, 2007

(call/cc call/cc)

Subyng posted:

If I'm converting from a float to double in C or C++, there shouldn't be any reason why I would lose precision, right?

No? Not unless you have a denormal and it rounds it to the smallest normal, or zero, before converting. I don't know that this happens, but it's the only exception I could come up with. (Might it also map negative zero to zero?)

Doghouse
Oct 22, 2004

I was playing Harvest Moon 64 with this kid who lived on my street and my cows were not doing well and I got so raged up and frustrated that my eyes welled up with tears and my friend was like are you crying dude. Are you crying because of the cows. I didn't understand the feeding mechanic.
I know it's part of the "solid" principles, but is there any kind of consensus in the dev community about if/when to use dependency injection in an application? Is there any real benefit besides how it makes unit testing possible/easier?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
There's theoretically other use-cases (being able to switch between two implementations of a dependency based on a config setting or for A/B testing or the like), but reducing the boilerplate involved in making it so that you can override dependencies for the sake of unit tests is definitely the primary benefit.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
Since some of you may find this useful as well:

Got tired of checking manually for new posts on threads, so i automated that bit with a little script and cron: https://github.com/wchristian/SomethingAwful-FreshBookmarks/blob/master/bookmarks.pl

Leandros
Dec 14, 2008

2 questions (C++ using mingw):

1) Is there a way to change the implementation of fmod()? Right now when I use it, fmod(x,y) with x<0 and y>0 gives me a negative number, i.e. the remainder from multiplying y with a negative number n such that ny is less negative than x. I want it to work so that it gives me the remainder of multiplying x with n-1. As a way to avoid this I'm currently using it as fmod(x+y,y) as |x|<|y| always, but speed is a must for me so if I can change the way fmod works it would be nice.

2) I have code occasionally crashing and I have no idea why it's happening. It happens when I allocate memory to an array of arrays. I declare it outside all functions as unsigned long** arr, later on making it arr = new unsigned long[L] and then in a for loop doing arr[i] = new unsigned long[Q] (Q is not constant for different i). The weird thing is, although I do have an RNG being seeded by time(0), nothing in that part of the code uses it, so all parameters are the same. Sometimes it crashes, sometimes it doesn't, and other times it crashes allocating another part of the array. I once got a message about bad_alloc() via the command prompt, but that only happened once. I've restarted my computer just in case but the problem persists. Any ideas? Is my RAM hosed? :ohdear:

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Leandros posted:

1) Is there a way to change the implementation of fmod()? Right now when I use it, fmod(x,y) with x<0 and y>0 gives me a negative number, i.e. the remainder from multiplying y with a negative number n such that ny is less negative than x. I want it to work so that it gives me the remainder of multiplying x with n-1. As a way to avoid this I'm currently using it as fmod(x+y,y) as |x|<|y| always, but speed is a must for me so if I can change the way fmod works it would be nice.

What kind of optimization are you doing that a single addition is an unacceptable speed penalty? Have you actually determined that this addition is slowing you down unacceptably? People are lousy at optimizing code unless they have a lot of experience at it.

quote:

2) I have code occasionally crashing and I have no idea why it's happening. It happens when I allocate memory to an array of arrays. I declare it outside all functions as unsigned long** arr, later on making it arr = new unsigned long[L] and then in a for loop doing arr[i] = new unsigned long[Q] (Q is not constant for different i). The weird thing is, although I do have an RNG being seeded by time(0), nothing in that part of the code uses it, so all parameters are the same. Sometimes it crashes, sometimes it doesn't, and other times it crashes allocating another part of the array. I once got a message about bad_alloc() via the command prompt, but that only happened once. I've restarted my computer just in case but the problem persists. Any ideas? Is my RAM hosed? :ohdear:

Your problem is elsewhere in your code. You are almost certainly doing a bad access into your array of arrays somewhere. The RNG is probably not related to the cause; the reason it's nondeterministic is because the initial state of memory is different each time you run the program. You need to run your program inside of a memory access analyzer which keeps track of what parts of the program are valid accesses and which are not. MSVC has a built-in debugger that can help with this; since you aren't using it, though, you might look into valgrind. Or just check all the places where you're doing memory accesses; you done hosed up in one of them at least.

JawnV6
Jul 4, 2004

So hot ...

Leandros posted:

unsigned long** arr, later on making it
arr = new unsigned long[L]
arr[i] = new unsigned long[Q]
Middle one should have one *

C++ has an amazing ability to make people utterly certain their code is correct and the entire computing world, from the compiler to the OS and even hardware, around them is crumbling instead.

Leandros
Dec 14, 2008

JawnV6 posted:

Middle one should have one *

C++ has an amazing ability to make people utterly certain their code is correct and the entire computing world, from the compiler to the OS and even hardware, around them is crumbling instead.

That's merely a typo here. The compiler would've thrown an error if it was that.

TooMuchAbstraction posted:

What kind of optimization are you doing that a single addition is an unacceptable speed penalty? Have you actually determined that this addition is slowing you down unacceptably? People are lousy at optimizing code unless they have a lot of experience at it.
I get that, there's probably far more places I could improve my code, and obviously addition isn't exactly a burden, but it's called about 10^9 times in a small run so I'd prefer to not have it there. Besides, if there's a simple way to change the implementation of fmod() I'd prefer it just because it looks nicer.


TooMuchAbstraction posted:

Your problem is elsewhere in your code. You are almost certainly doing a bad access into your array of arrays somewhere. The RNG is probably not related to the cause; the reason it's nondeterministic is because the initial state of memory is different each time you run the program. You need to run your program inside of a memory access analyzer which keeps track of what parts of the program are valid accesses and which are not. MSVC has a built-in debugger that can help with this; since you aren't using it, though, you might look into valgrind. Or just check all the places where you're doing memory accesses; you done hosed up in one of them at least.
Alright, but then why does the code crash when I'm creating an array? The index used to address the first dimension is not out of bounds, of that I am certain.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
I'm going to go out on a limb and suggest that you probably don't actually want a standard, commonly-used function to suddenly work completely differently in your codebase than it does everywhere else. That's just going to result in hair-pulling later on when someone tries to figure out why their numeric algorithm is giving them totally wrong results.

Have you benchmarked whether removing the addition results in a measurable performance improvement, or are you just guessing? The addition is likely to be an order of magnitude faster than the fmod operation itself...

JawnV6
Jul 4, 2004

So hot ...

Leandros posted:

That's merely a typo here. The compiler would've thrown an error if it was that.
Debugging C++ code remotely is hard enough that I thought you would've taken the time to check for that. You probably could gotten it past compilation with a cast, but again just posting your code somewhere would be a far better workflow than "guess and check with typos". The type of crash you're describing is exactly what would happen if you started dereferencing longs as pointers.

Leandros posted:

I get that, there's probably far more places I could improve my code, and obviously addition isn't exactly a burden, but it's called about 10^9 times in a small run so I'd prefer to not have it there. Besides, if there's a simple way to change the implementation of fmod() I'd prefer it just because it looks nicer.
10^9 sounds really big until you realize that your processor does four times that many cycles every second. Does each run take more than a second? Have you actually benchmarked how long fmod takes? Have you imagined any conceivable implementation of fmod that allows for your flexibility without taking more time than a single integer operation without any control flow modification?

fritz
Jul 26, 2003

Leandros posted:

2 questions (C++ using mingw):

2) I have code occasionally crashing and I have no idea why it's happening. It happens when I allocate memory to an array of arrays. I declare it outside all functions as unsigned long** arr, later on making it arr = new unsigned long[L] and then in a for loop doing arr[i] = new unsigned long[Q] (Q is not constant for different i). The weird thing is, although I do have an RNG being seeded by time(0), nothing in that part of the code uses it, so all parameters are the same. Sometimes it crashes, sometimes it doesn't, and other times it crashes allocating another part of the array. I once got a message about bad_alloc() via the command prompt, but that only happened once. I've restarted my computer just in case but the problem persists. Any ideas? Is my RAM hosed? :ohdear:

Point one: the things external (ram, compiler, system, etcetc) is never bad unless you are absolutely rock solid certain you have eliminated all other possibilities in your code. You are not there yet.
Point two: If you're compiling with mingw, you're doing something unixy. Get a real unix machine or a vm, and use valgrind.
Point two+: Get visual studio and use their debuggers instead.
Point three: how close are you to the edge that you need to do this kind of memory trickery.


Leandros posted:

1) Is there a way to change the implementation of fmod()? Right now when I use it, fmod(x,y) with x<0 and y>0 gives me a negative number, i.e. the remainder from multiplying y with a negative number n such that ny is less negative than x. I want it to work so that it gives me the remainder of multiplying x with n-1. As a way to avoid this I'm currently using it as fmod(x+y,y) as |x|<|y| always, but speed is a must for me so if I can change the way fmod works it would be nice.

You will regret doing this, and additionally it will not give you the speed improvements you want.

Xerophyte
Mar 17, 2008

This space intentionally left blank
In general: IEEE requires that implementations provide the floating point remainder x–(round(x/y)·y). If you get anything else (like fmod) it's a bonus.

For X86: fmod and remainder map or or less directly to the two partial remainder functions FPREM and FPREM1. The advanced instruction sets can do the two corresponding remainder operations in one instruction (FPREM and FPREM1 are partial remainders, hence the P, and require loops) and vectorize them but do not, to my knowledge, offer any other remainders. You can't change the behavior and keep the performance.

If you want more performance, 1: parallelize and 2: vectorize.

Mycroft Holmes
Mar 26, 2010

by Azathoth
How the gently caress do I create a sidebar? I cannot get my code to work right. It's supposed to work like this:

<header>
<nav>
<sidebar><content>

How do I get my sidebar and my content next to each other? I floated the nav menu left, the sidebar left, and the content right. It's not working and I want to hurt something.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Need to see code, the relevant CSS and HTML to see where you've mis-stepped.

TheresaJayne
Jul 1, 2011

Mycroft Holmes posted:

How the gently caress do I create a sidebar? I cannot get my code to work right. It's supposed to work like this:

<header>
<nav>
<sidebar><content>

How do I get my sidebar and my content next to each other? I floated the nav menu left, the sidebar left, and the content right. It's not working and I want to hurt something.

set the size of the sidebar to a percent width="20%"

then with the float left it should work, otherwise its going to fill the full window.

a hint - use the debug tools in chrome to edit css to try things out (f12 in firefox as well)

Mycroft Holmes
Mar 26, 2010

by Azathoth

Maluco Marinero posted:

Need to see code, the relevant CSS and HTML to see where you've mis-stepped.

edit.

Mycroft Holmes fucked around with this message at 08:37 on Mar 3, 2016

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Yeah, so you have no widths set. You want to set the width of your sidebar, and then also the width of the content area. I means there's a lot more to it than that, and you could also use new hotness like flexbox, but just setting widths will do for now.

TheresaJayne
Jul 1, 2011

Mycroft Holmes posted:

Should have put it in code blocks but it works fine like this


I removed div4 as i couldnt work out where you wanted it - if its supposed to be on the right then you contain everything on the right in another div which is the column wrapper
so using divs you create the left column/right column and then you can put whatever you want in there

code:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<title>Crowdsourcing History</title>
</head>
<body>
<div id="div1">
<div id="div2">
<h1><img src="at_sign.png" style="width:42px;height:42px;">Slogans are for nerds<h1>
</div>
<div id="div3">
<ul>
<li><a href="history.html">History</a></li>
<li><a href="types.html">Types of Crowdsourcing</a></li>
<li><a href="ethics.html">Ethical Issues in Crowdsourcing</a></li>
</ul>
</div>
<div id="div5">
<h2>History</h2>
<p>The term "crowdsourcing" is a portmanteau of "crowd" and "outsourcing," coined by Steve Jurvetson online and then published by Jeff Howe in a June 2006 Wired magazine article "The Rise of Crowdsourcing".[1] It has been argued that crowdsourcing can only exist on the Internet and is thus a relatively recent phenomenon;[3] however, long before modern crowdsourcing systems were developed, there were a number of notable examples of projects that utilized distributed people to help accomplish tasks. Historical examples include:</p>
<h2>The Oxford English Dictionary</h2>
<p>The Oxford English Dictionary (OED) may provide one of the earliest examples of crowdsourcing. An open call was made to the community for contributions by volunteers to index all words in the English language and example quotations of their usages for each one. They received over 6 million submissions over a period of 70 years. The making of the OED is detailed in The Surgeon of Crowthorne, by Simon Winchester.[7]</p>
<h2>Early crowdsourcing competitions</h2>
<p>Crowdsourcing has often been used in the past as a competition in order to discover a solution. The French government proposed several of these competitions, often rewarded with Montyon Prizes, created for poor Frenchmen who had done virtuous acts.[9] These included the Leblanc process, or the Alkali Prize, where a reward was provided for separating the salt from the alkali, and the Fourneyron's Turbine, when the first hydraulic commercial turbine was developed.[10]<br><br>In response to a challenge from the French government, Nicholas Appert won a prize for inventing a new way of food preservation that involved sealing food in air-tight jars.[11] The British government provided a similar reward to find an easy way to determine a ship's longitude in the The Longitude Prize. During the Great Depression, out-of-work clerks tabulated higher mathematical functions in the Mathematical Tables Project as an outreach project.[12]</p>
</div>
</div>
</body>
</html>
code:

body{
background-color: gray;
}

p{
font-family: "Times New Roman", Times, serif;
}

h1{
font-family: "Times New Roman", Times, serif;
text-align: center;
}

h2{
font-family: "Times New Roman", Times, serif;
}

ul{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #dddddd;
}

li{
float: left;
}

a{
display: block;
padding: 8px;
}

a:link{
color: black
}

a:visited{
color: blue;
}

a:hover{
background-color: gray;
}

#div1{
background-color: white;
width: 1000px;
margin: auto;
}

#div2{

}

#div3{
	width: 20%;
}

#div4{
float: left;
width: 20%;
}

#div5{
float: right;
width: 80%;
background-color: white;
} 

TheresaJayne fucked around with this message at 08:17 on Mar 3, 2016

Mycroft Holmes
Mar 26, 2010

by Azathoth
Thank you for your help.

Shaman Tank Spec
Dec 26, 2003

*blep*



HappyHippo posted:

This is a typical experience, but keep at it and eventually things will start clicking. The functional paradigm is different enough that it's almost like learning programming all over again.

Yeah, it's encouraging to hear others have gone through the same and it's not just me being a loving idiot :) Thanks, guys!

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

Der Shovel posted:

Yeah, it's encouraging to hear others have gone through the same and it's not just me being a loving idiot :) Thanks, guys!

Yeah, it took me quite a while too. The best advice I can give is try to work backwards from how you normally would. Start at the end, draw up the most complex data structure assuming you have any function you need along the way. Then start building those repeating the same process until you eventually get down to really simple components that are trivial to implement.

tweet my meat
Oct 2, 2013

yospos
So I'm taking a beginner c++ class and we're currently doing an assignment involving switch case statements. I have the gist of how the syntax is laid out I think, but I get an odd error when I actually compile and run the program. I've been trying to root out the problem, but I don't fully understand the logic that makes it work, so it's a little tough. The code was modified from a previous assignment that used an if/else statement to the same effect.
Could someone explain what is happening just from a quick glance?

The code
code:
#include <iostream>
#include <iomanip>
/*
Author:some dumb nerd
Date Written:3/2/2016
Purpose:Calculate number of hours required for a specified major (modified from previous code to include a switch case statement)
*/
 
using namespace std;
 
int main()
{
int hours;
char major;
 
cout << left << setprecision (2) << fixed;
cout << "CIS" << endl << "OFAD" << endl << "BUS" << endl << "NURS" << endl << endl << "Please select Major:";
cin  >> major;
 
switch (major)
{
case 'CIS':
    hours=100;
    break;
case 'OFAD':
    hours=70;
    break;
case 'BUS':
    hours=80;
    break;
case 'NURS':
    hours=125;
    break;
default:
    hours=0;
    major='Invalid';
}
 
cout << major << endl << setw(30) << "Selected Major is" << major << endl << setw(30) << "Hours required:" << hours;
    return 0;
}
The error. "d" should read "CIS" in both spots and hours in the case of CIS hours should read 100. My guess is that it's taking the d at the end of invalid, but I'm not sure why.

tweet my meat fucked around with this message at 04:46 on Mar 4, 2016

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Sergeant_Crunch posted:

The error. "d" should read "CIS" in both spots and hours in the case of CIS hours should read 100. My guess is that it's taking the d at the end of invalid, but I'm not sure why.

What is the type of the variable "major"? What kind of information are you trying to store in that variable?

kloa
Feb 14, 2007


TooMuchAbstraction posted:

What is the type of the variable "major"? What kind of information are you trying to store in that variable?

I was about to answer his question, but I like your style.

tweet my meat
Oct 2, 2013

yospos
It's a character, and I'm trying to store text characters in it I think (CIS, BUS, etc) Is it something really obvious related to how char works? I used a string for the variable type on the previous program, but apparently that doesn't work with switch case statements. This is honestly the first time I've used character as a variable type since most of the previous programs have been pure numbers.

tweet my meat
Oct 2, 2013

yospos
Ok looking at it more closely I see that it's reading "d" as the input when I input "CIS" so it's reading the variable major as the wrong thing. The problem isn't in the switch case statement, or at least not this particular problem it's in some of the code before it I think.
I'm not really sure why though, can char only handle one letter or something?

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
You've got two problems (or really, the same problem twice.) One is when you read in major; the other is in the switch statement (specifically, in the default block.)

What is a character?

tweet my meat
Oct 2, 2013

yospos
I'm gonna guess that a character can only be a single character and not multiple. Do I need to modify it so that it accepts a letter or number as the input and have a separate variable for the major and selection? I'll go ahead and give that a shot.

e:Doing that made the program work, thanks! I'm pretty sure I get it, but I'll ask anyways. Was that the reason it wasn't working or did I stumble on to the solution without really understanding it?

tweet my meat fucked around with this message at 06:57 on Mar 4, 2016

Adbot
ADBOT LOVES YOU

TheresaJayne
Jul 1, 2011

Sergeant_Crunch posted:

I'm gonna guess that a character can only be a single character and not multiple. Do I need to modify it so that it accepts a letter or number as the input and have a separate variable for the major and selection? I'll go ahead and give that a shot.

e:Doing that made the program work, thanks! I'm pretty sure I get it, but I'll ask anyways. Was that the reason it wasn't working or did I stumble on to the solution without really understanding it?

well char is a single character

char test = 'w';

for a String you need an array of chars

char* test = "WIN";

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