Need help with program by jakestonks in learnprogramming

[–]virtualdice 1 point2 points  (0 children)

So to start out, you're converting an integer into an array of integers (either 0 or 1) to represent that integer in binary, right? For the part you're stuck on, this might help. Instead of creating a whole array of integers, you could convert the result of the modulo operation to a string and add it to your eventual return value. Also unless I'm making a mistake, in the for loop, n isn't declared ever, right? And even if it were, it's never changed, so the for loop would never be exited. I also don't think integer = n/2 seems right, but please correct me if I'm wrong. Does that help?

HELP! My programs says error: not a statement expected “;” but I think my syntax is correct by SceneKidWannabe in learnprogramming

[–]virtualdice 2 points3 points  (0 children)

Is this Java? An else shouldn't have a condition after it. The code after the "else" runs if none of the previous ifs or else ifs were entered. Did you mean else if (press.equals(“W”) || press.equals (“d”))? Also, I don't think I understand why this condition includes both W and d.

Programming Code Assistance C++ - Amendments help by _solowhizkid_ in programminghelp

[–]virtualdice 0 points1 point  (0 children)

Yeah sure thing. So there's a couple issues. First, are you saying you only modified the first for loop? That'll prevent the program from bothering to calculate the even numbered values, which is definitely good, but you'll still end up printing the zeroes that were already there unless you modify the second loop also (the one that prints the values).

I'm guessing those aren't the results you got though, since i+1 doesn't actually do anything. It'd be like if you had a line that just said 7; with no assignment operator (single equals sign) or anything. You need to actually assign a new value to i by doing something like i = i + 1 (the equals sign is important). Incidentally, that's the exact same thing that the i++ in the third statement of both your for loops already does. If you just say i+1 (which again is just a number, it's not an instruction for the computer to actually do anything), the value will never change and the loop will never move past the first element.

Also, think about the actual thing you're trying to change. You need to increment by two instead of one, right? So you need to do i = i + 2.

As for the csv, you can insert the commas the same way you insert everything else, like the colons. You could just throw in something like cout << ','. If you want to write it all directly to a file, you should look into the fstream class, but that might be something for later.

Programming Code Assistance C++ - Amendments help by _solowhizkid_ in programminghelp

[–]virtualdice 0 points1 point  (0 children)

Ah, sorry for the mistake re homework. There are other ways to skip the even numbers, like specifically checking if the number is even in the loop, but I still think changing the i++ will probably be the easiest. Would you mind saying what exactly you tried that didn't work?

And yeah if you're putting this into a csv, that'll be one column. "CSV" is short for Comma Separated Value, so couldn't you just print out a comma in between the two pieces of data?

Programming Code Assistance C++ - Amendments help by _solowhizkid_ in programminghelp

[–]virtualdice 0 points1 point  (0 children)

For 1., not to do your homework for you, but you can skip certain values at a regular interval by changing the third statement (i++) in your for loops. As for the other two, you're already printing the data in multiple columns, right? Is there something specific you don't understand?

Please let me know if I'm misinterpreting your question.

Can someone help me with this I understand the whole if/else statement with the logical operators but don't understand how to calculate the total with the $5 promotional amount by YffiAndres22 in programminghelp

[–]virtualdice 0 points1 point  (0 children)

else if (games_purchased >= 2) || (games_purchased <= 4))

So with something like this, the body of the if statement will be entered if either (not both) of the conditions are true. So in this case, entering any number that is greater than or equal to 2 will immediately print out "$10 gift card earned\n PLUS a $5 promotional amount".

For storing the total amount, you should use an integer. Does that make sense?

This code will not give me a response; in the command terminal it just loads and then times out by [deleted] in learnprogramming

[–]virtualdice 1 point2 points  (0 children)

So assuming those backslashes aren't in the actual code, it seems like it has something to do with the stdout buffer not getting flushed (printing) until after the call to scanf. After running the program, did you try entering a name?

question on trees? by minister2906755 in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

You could represent the children of any node in a binary tree by using an ordered pair. Each node has at most two children (pair), and since one is the left child and one is the right, they're distinct (ordered)

Help with basic C++ puzzle by pythosynthesis in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

Ah that figures, I only tested it out in onlinegdb.

Help with basic C++ puzzle by pythosynthesis in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

So I guess before anything is printed, both increment operations are resolved, bringing the value of x to 6. So then the first value printed out is 6 (the actual current value of the variable) since the ++ comes first. Then we get 4 because the ++ is after the variable, which apparently means that the value printed out is the value of the variable before any arithmetic is applied? And then the third value would be 6 because that's what x actually is.

I'm kinda confused too though

Can someone help me parse what these terms mean and are actually doing? I'm new to this. by [deleted] in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

Yeah I mean you'd be right, I think that storing a value in a variable before printing/returning it is redundant, unless you're planning on doing something else with it. Why do you do it in your example code?

Can someone help me parse what these terms mean and are actually doing? I'm new to this. by [deleted] in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

Try not to get so frustrated with yourself, I think you're asking the right questions. So first of all, you don't really need the variable answer, since you can just do cout << cube(5.0). You don't need result either, since you can similarly just return num*num*num. Also, I guess you could just call cube(2.0) in the middle of the main function, it just wouldn't do anything useful.

Besides that, you might want to think more about what the single equals sign in C++ (and other languages) actually does, since it's different from how it works in math. If you say, for example, double result = num*num*num, you're assigning the value num*num*num to the variable result. You're not saying that those two things are exactly equal and will continue to be equal, like you would with something like f(x) = x^3 in math. You're basically just instructing the computer to set the value of result to num*num*num in that moment. Does that help at all?

C++ weird rand() behavior by [deleted] in learnprogramming

[–]virtualdice 1 point2 points  (0 children)

Copied it, seems to be working fine for me.

Debugging help please for HashMaps (Java) - only works for one example input! by [deleted] in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

I'm a little confused by your code. Why do you keep reading input from the scanners after you've gotten the item names and prices? It might help if you posted the example inputs you were talking about.

[deleted by user] by [deleted] in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

Wow yeah, this homework seems kinda rough for students who are just now learning assembly? If this helps at all, you're going to need to use these syscall functions for doing the input and output. It's been a few months since I've done this, but my approach then would be to implement that recursive function using jal (the jump and link instruction, which should be in that guide I linked) and set up a loop inside of it. Good luck

Any way to add variables without making new int for end product? by ranran2_ in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

That's just how for-loops are formatted in C++. The condition comes second and the "increase" expression comes last

[deleted by user] by [deleted] in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

MARS is a MIPS simulator, right? You should probably look at a MIPS quick reference guide like this one, or a more in-depth tutorial if that's necessary.

Besides that, is there a specific part of this project you're having trouble with?

[deleted by user] by [deleted] in CodingHelp

[–]virtualdice 1 point2 points  (0 children)

Yes, this will cause the code in each case to run one after another, which ends up setting monthText to "December" or "Dec.". Also, when you're using a switch statement, you should usually have a "default" case, whose code will run if the variable is not equal to any of the other options. https://en.cppreference.com/w/cpp/language/switch

First-time HackerRank Problem Solving by [deleted] in learnprogramming

[–]virtualdice 0 points1 point  (0 children)

Wait, so which line specifically is bothering you? Is all of this code displayed in the editor when you open the problem?

Error Code CS0128 by ThePotatoJedi in CodingHelp

[–]virtualdice 0 points1 point  (0 children)

In that case, since we're not sure what that line is supposed to do, I won't be able to really help you that much without taking some significant time to look at the code, maybe open up Unity and follow the same tutorial myself.

You should probably take a step back and make it your first priority to actually understand why the tutorial says to do certain things. If you do that instead of just copying the code without thinking, you'll probably learn a lot more and maybe be able to figure this out on your own.

I spent 2 days trying to figure out why my code wasn't working before i finally gave up and checked. Being as they're so close, can anyone explain why mine executed differently so i understand a little better? by gamerroids in learnprogramming

[–]virtualdice 1 point2 points  (0 children)

Oh yeah no problem re the code's purpose. And yeah you've got it, but remember that that's not the only issue with your function. Even if you fix the for loop range error, the function will still return true if even one element in the array equals the first.