|
Zopotantor posted:Actually void is the type that is called 'unit' in functional languages. Void functions return to their caller, but the 'value' they return is not used. Bottom is the conceptual return type of functions that don't return, not even a useless value. void isn't unit, but its also not really bottom either. I can't put something of type void in a struct (whereas i could put something of type struct Unit {}; ) so nothing inhabits its type unless you kind of pretend it does. but I also can write a series of functions that that all return void and it type checks and executes. thats probably because c++ is c++ and the semicolon isnt actually a monad and thats why you have a special rule in there to make it work.
|
# ? Jun 6, 2015 18:14 |
|
|
# ? Jun 8, 2024 06:44 |
|
I'm trying to write a simple program that converts an entered number from 1 to 100 to roman numerals. We can't use recursion or arrays yet. The code compiles but It only prints "C" (100), regardless of the value entered for n. Why would this happen?C code:
Modulo16 fucked around with this message at 19:37 on Jun 8, 2015 |
# ? Jun 8, 2015 19:31 |
|
Frank Viola posted:I'm trying to write a simple program that converts an entered number from 1 to 100 to roman numerals. We can't use recursion or arrays yet. The code compiles but It only prints "C" (100), regardless of the value entered for n. Why would this happen? The comma operator does not do what you think it does. You need to use && instead. Oh, and your use of "return" also looks suspicious. You may want to replace it with "continue". Zopotantor fucked around with this message at 19:46 on Jun 8, 2015 |
# ? Jun 8, 2015 19:43 |
|
You also need to learn the difference between assignment (=) and equality (==). You also probably do not want to return n from main.
|
# ? Jun 8, 2015 19:46 |
|
Also, look carefully at your if statements. if(n=100) sets n to 100. You'd want two equals signs there to test for equivalence. e;f,b
|
# ? Jun 8, 2015 19:47 |
|
Zopotantor posted:The comma operator does not do what you think it does. rjmccall posted:You also need to learn the difference between assignment (=) and equality (==). I have applied both changes, but the values don't correspond to the input. i.e. input of 32 yields XXX not XXXII
|
# ? Jun 8, 2015 19:53 |
|
Frank Viola posted:I have applied both changes, but the values don't correspond to the input. Just to be clear here, there were three changes suggested there, did you do all three?
|
# ? Jun 8, 2015 20:20 |
|
Yes. I now understand the difference between assignment and equality, why the comma doesn't do what I thought it did and why it was necessary to do &&, and that returning n is not recommended. Continue only caused an infinite loop. Modulo16 fucked around with this message at 20:27 on Jun 8, 2015 |
# ? Jun 8, 2015 20:24 |
|
Post the changes you made, if you change all returns to continue, and change the assignment operators in the if-statement-condition to the equality operator, as well as changing the commas to && (again in the if-condition) then it will work fine, the only time you would be stuck in the loop is if n is being set to something higher than 0 and not decremented to 0 in a reachable statement (I'm guessing you either missed an assignment operator or changed the assignment operator inside the if-block to an equality operator accidentally).
|
# ? Jun 8, 2015 20:53 |
|
JawKnee posted:Post the changes you made, if you change all returns to continue, and change the assignment operators in the if-statement-condition to the equality operator, as well as changing the commas to && (again in the if-condition) then it will work fine, the only time you would be stuck in the loop is if n is being set to something higher than 0 and not decremented to 0 in a reachable statement (I'm guessing you either missed an assignment operator or changed the assignment operator inside the if-block to an equality operator accidentally). Check what happens if n is, e.g., 30.
|
# ? Jun 8, 2015 21:05 |
|
Zopotantor posted:Check what happens if n is, e.g., 30. ahh I didn't read close enough there.
|
# ? Jun 8, 2015 21:06 |
|
JawKnee posted:ahh I didn't read close enough there. code:
JawKnee posted:Post the changes you made, if you change all returns to continue, and change the assignment operators in the if-statement-condition to the equality operator, as well as changing the commas to && (again in the if-condition) then it will work fine, the only time you would be stuck in the loop is if n is being set to something higher than 0 and not decremented to 0 in a reachable statement (I'm guessing you either missed an assignment operator or changed the assignment operator inside the if-block to an equality operator accidentally).
|
# ? Jun 9, 2015 02:53 |
|
== is not assignment.
|
# ? Jun 9, 2015 03:05 |
|
Dessert Rose posted:== is not assignment. the if statements are to test for equality. if the integer satisfies the condition it prints, otherwise it doesn't why would I need to assign any number value when I am trying to get it to satisfy the conditions of 1 if or else if statement? I need it to satisfy on statement, then move down to the ranges of 1-9 if they are present in the number.
|
# ? Jun 9, 2015 03:24 |
|
== is for testing equality, but assigns no value. You appear to be attempting to use it to assign a value in the code. Because of how C/C++ works, this means a statement like (and I quote): code:
Further, your return statement for your main() function is within your while loop, and will end after the first check through the if/else chain Evil_Greven fucked around with this message at 03:36 on Jun 9, 2015 |
# ? Jun 9, 2015 03:31 |
|
You need to alter the number that you are checking at each iteration of the while loop if you ever want it to terminate (that number being n) so if you want to check for an equality in your if-condition (if A is equal to B): if( A == B), however if you want to set a variable to be equal to some value (set n equal to n minus A): n = n - A There are two other issues here, take a look at the condition in your while loop: code:
finally, you have: code:
|
# ? Jun 9, 2015 03:37 |
|
Evil_Greven posted:== is for testing equality, but assigns no value. would n-=100 be a better choice? And how do I get the while loop to execute again? C code:
Modulo16 fucked around with this message at 03:42 on Jun 9, 2015 |
# ? Jun 9, 2015 03:38 |
|
while loops will continue to execute for as long as their condition resolves to true, provided it isn't explicitly broken by a break; or return <something>; call.
|
# ? Jun 9, 2015 03:41 |
|
JawKnee posted:while loops will continue to execute for as long as their condition resolves to true, provided it isn't explicitly broken by a break; or return <something>; call. I removed the return and it solved the problem. Thanks dudes, I actually learned more from this than from the TA that teaches the class!
|
# ? Jun 9, 2015 03:44 |
|
Frank Viola posted:would n-=100 be a better choice? That would work, so would code:
|
# ? Jun 9, 2015 03:44 |
|
You also have the problem of doingC++ code:
when it should be C++ code:
or even just C++ code:
since n is guaranteed to be less than 100 if control reaches the else if statement.
|
# ? Jun 9, 2015 04:17 |
|
Doc Block posted:
If you do this, you don't even need the while loop. Just get rid of all the else keywords.
|
# ? Jun 9, 2015 14:31 |
|
I'm surprised no one has attempted to do this as a one-liner yet.
|
# ? Jun 9, 2015 14:37 |
|
Slash posted:I'm surprised no one has attempted to do this as a one-liner yet. Knuth needed 20 lines for it in TeX, so I'm not going to try.
|
# ? Jun 9, 2015 18:52 |
|
Zopotantor posted:Knuth needed 20 lines for it in TeX, so I'm not going to try. That's no justification.
|
# ? Jun 9, 2015 19:42 |
|
code:
sarehu fucked around with this message at 20:24 on Jun 9, 2015 |
# ? Jun 9, 2015 20:22 |
|
Subjunctive posted:That's no justification. Justification takes even more code, man.
|
# ? Jun 9, 2015 20:29 |
|
code:
code:
sarehu fucked around with this message at 21:55 on Jun 9, 2015 |
# ? Jun 9, 2015 20:47 |
|
An interesting report on the status of C++17: https://botondballo.wordpress.com/2015/06/05/trip-report-c-standards-meeting-in-lenexa-may-2015/
|
# ? Jun 10, 2015 00:36 |
Subjunctive posted:An interesting report on the status of C++17: https://botondballo.wordpress.com/2015/06/05/trip-report-c-standards-meeting-in-lenexa-may-2015/ This was really interesting. I'm sad that modules probably aren't going to make it by C++17, but it looks like a lot of the stuff that will make it will be really good. Thanks!
|
|
# ? Jun 10, 2015 00:51 |
|
I'm so glad I'm not the poor human who has to drive the filesystem spec.
|
# ? Jun 10, 2015 00:54 |
|
I'm mostly glad that they're really aiming for shipping something in 2017 rather than delaying it for big items.
|
# ? Jun 10, 2015 00:54 |
|
Fixed-date release cycles are the truth and the light.
|
# ? Jun 10, 2015 00:56 |
|
Subjunctive posted:I'm so glad I'm not the poor human who has to drive the filesystem spec.
|
# ? Jun 10, 2015 00:58 |
|
Yeah, I think that it makes sense that they chose mediocre over Byzantine, it's just gotta be a bad job to navigate that process.
|
# ? Jun 10, 2015 01:00 |
|
Subjunctive posted:An interesting report on the status of C++17: https://botondballo.wordpress.com/2015/06/05/trip-report-c-standards-meeting-in-lenexa-may-2015/ So, does "voted out for publication" mean it's in?
|
# ? Jun 10, 2015 06:11 |
|
Yeah, means they voted to publish it as a TS, I believe.
|
# ? Jun 10, 2015 06:32 |
|
Ok I have another (dumb) LLDB question: Why does stepping into a method seem to land me in a random spot inside the method/source file? I've got a class with several .cpp files each with a method. When I step into one, LLDB puts me in line 81 of the file even though it should start at line ~26 or so. All of the variables I have in the class are wrong when I print them, too. Then when I step again it puts me where it should have started and then all the variables make sense. Do I just not understand how LLDB handles stepping? I figured it should just put me right inside the method when I step into it.
|
# ? Jun 11, 2015 22:29 |
|
Eeyo posted:Ok I have another (dumb) LLDB question: It might just be a bug, or there might be some implicit behavior at the start of the function that you're stepping through.
|
# ? Jun 12, 2015 01:37 |
|
|
# ? Jun 8, 2024 06:44 |
|
I don't know how lldb handles C++, but Visual Studio's debugger has a "step" on the opening curly brace of a class method before the this pointer gets initialized, at which point your ivars are going to be corrupt because you're accessing them through an uninitialized pointer to who knows where.
|
# ? Jun 12, 2015 02:40 |