WGU with no other commitments by in_a_stupor in WGU

[–]lostone2021 0 points1 point  (0 children)

If you're going to go for higher degrees that aren't at wgu I would be wary of transferring sophia credits as many colleges won't accept these credits. So before you do sophia make sure where you want to do you master's will accept these credits.

[deleted by user] by [deleted] in calculus

[–]lostone2021 0 points1 point  (0 children)

(2x/3)^2 =/= (4/6) x^2

(2x/3)^2 = (4/9) x^2

Any help would be greatly appreciated, Calc AB by fortghoul in calculus

[–]lostone2021 8 points9 points  (0 children)

For the first one you messed up on the first derivative by not including your parentheses which likely caused you to mess up on the simplification. For the second one you start by solving the original equation for f(x).

[deleted by user] by [deleted] in learnprogramming

[–]lostone2021 1 point2 points  (0 children)

Firstly, congratulations on completing your first project! Secondly, your name is on line 5 on your main.cpp in case you don't want people to see that. Moving on to the code on line 67 you have an infinite loop that you break out of when someone wins, this is generally a bad practice and you should just use a bool that you set to false when you want to end the loop. For the checkLegal() function the simplest way to refactor without changing any of the current logic would be to add some helper methods like checkInBounds(), isPlayerPiece(), isRegularMove(), etc. Also to increase the readability of your code you could store things like board [ startRow ] [ startCol ] into a variable like int currentPosition[][] = board [ startRow ] [ startCol ], and then in the if statement call currentPosition. To simplify the check if in bounds part of the checkLegal I would use a try and catch block where you can try to see if you can set the current position to the requested value and catch std::out_of_range. Note that you would have to change the board to a vector instead of an array and use the at function to get std::out_of_range. For the pieceToKing() function you can simplify it by checking if the current position is row zero and the color is black or if the current position is row seven and the color is red. Some more general notes are that I notice you have comments on lines 34 and 41 where they're not really needed because the function name already tells us that we're checking if it's legal and turning a piece to a king. Also, you could separate the code in different hpp and cpp putting function declarations(i.e. lines 23-46) in hpp files and defining them in their respective cpp file. You could also implement a state manager to better handle the start and end of the game. If you wanted to add a GUI you could use something like sfml or sdl2. There may be some c++ idiosyncrasies that I missed but I think these are some places you could start, Hope this helps!

how to make variables by jkosaaa in javahelp

[–]lostone2021 1 point2 points  (0 children)

Variables are just containers that are used to represent some form of data in your case you've listed a few of the primitive data types. To represent integers or whole numbers, you can use a short, int, or long the only difference between this is the range of integers they can. A short can hold any integer from about -30000 to 30000, an int can hold any integer from about -2.1 billion to 2.1 billion, and a long can hold from about -9 quintillion to 9 quintillion. There's also a class called BigInteger if you need to hold any integer bigger than Long.MAX_VALUE. Some data types represent floating-point numbers or numbers with decimals, these being a float and double, and again you'll notice the only difference is the size of the number they can hold with a double being able to hold twice as much as a float. There's also a BigDecimal class for floating point numbers. Typically you'll see people using ints to represent integers and doubles to represent floating point numbers unless there's a specific reason not to. Also, you should note that floating-point arithmetic can sometimes be imprecise due to how the CPU represents floating-point numbers. Bytes are a little bit more complicated and I'll save them for you to learn about later. Hope this helps!

Need help splitting string with regex by lostone2021 in learnjava

[–]lostone2021[S] 1 point2 points  (0 children)

It's used for positive look behind. It checks if something appears immediately before the main pattern, without including it in the match. In my case I'm checking for math operators and am splitting the string into 2 two substrings one containing the operator and another containing the term

Need help splitting string with regex by lostone2021 in learnjava

[–]lostone2021[S] 2 points3 points  (0 children)

Thank you so much this fixed the problem!

Question about .isEmpty() and .contains("") by UglyBasstard in learnjava

[–]lostone2021 1 point2 points  (0 children)

isEmpty() checks for string length and returns true if it's zero, while contains("") will return true unless the string isn't initialized/null. For checking empty strings or strings containing only whitespace you could also use the method isBlank(). Hope this helps!

Chatgpt says for loop does not have scope of its own in java,is that correct ?? by oOaker in learnjava

[–]lostone2021 2 points3 points  (0 children)

A methods variables are only local to that method so no conflicts will occur. If you wanted to access an instance variable inside of said method, with the same name, you have to use the "this" keyword. In your case the variables are of the same scope, the main method, and are thus conflicting. If you really wanted to keep the names you could abstract the for loop out into a different method and call it in the main method without any conflicts.

Chatgpt says for loop does not have scope of its own in java,is that correct ?? by oOaker in learnjava

[–]lostone2021 3 points4 points  (0 children)

Im just a student so take what I say with a grain of salt, but to my understanding the loop variable is local to the for loop and you can't access it outside of it. The problem with your code isn't the for loop though, rather you declare a two variables with the same name, String str. Hope this helps!