…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
… <cstdio> using namespace std; //Function Prototype Declaration int next… Reply by Sherwin_4
4 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
…{ if (value <= 0) break; std::cout << value <…" "; value = next(value); } std::cout << "count…<< count << std::endl; } Reply by nullptr
4 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
…> #include <vector> using namespace std; //Function Prototype Declaration int… Reply by Sherwin_4
4 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
… <iostream> using namespace std; //Function Prototype Declaration int next… Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
…> #include <vector> using namespace std; //Function Prototype Declaration int… Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Not sure what I'm doing wrong, I get this output: What number shall I start with? 8 The hailstone sequence starting at 8 is: 8 4 2 1 The length of the sequence is 4. The largest number in the sequence is 8. The longest hailstone sequence … Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Is "inital" a typo and supposed to spell as "initial" or does it stand for something else? I kept the name as is. No need for temp1 or inital2. They just add to the length and the complexity and increase the chance of mistakes. … Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Oh wow, definitely a typo! I'll change that. I figured out what was wrong. Here is the code for the function below: int initialcomp_Num(int n) { int count, initial, start; //Function will … Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
I assume the lines with only a bracket don't count as a line, right? I entered 7 into your program and got this line... > What number shall I start with? 7 > 7 > The hailstone sequence starting at 7 is: > 7 22 11 34 17 52 26 13 40 … Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
A small point: line 8 you `return` in the `if` construct, so the `else` and its associated brackets are redundant. This is a very common pattern (it's called a [guard](http://wiki.c2.com/?GuardClause) )... myFunction(params) { if (there… Reply by JamesCherrill
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
… <cstdio> using namespace std; //Function Prototype Declaration int next… Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Nevermind, I figured out the issue. For one, I need some sleep. Below is the recovery: int sequence_Max(int n) { //Variable Declaration. int max = n, temp = n; //temp = n; while (temp … Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
> I couldn't have 'n' = next(n) because it would be changing the parameter Who says you can't change the parameter? int sequence_Max(int n) { //Variable Declaration. int max = n; if ( n <= 1) {… Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
And you can actually take out the `if(n <=1)` guard above. It has no effect. The while loop below it handles it. Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Although it's true that you can omit the guard, I would argue for leaving it in. When you're reading a recursive method the first question is (how) does it Terminate? I would be very happy to see that right up front. For me readability trumps efficiency … Reply by JamesCherrill
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
The professor doesn't like to see the starting parameters change value in the function (same with the noncomment lines requirement). I'm not sure if this is a real world thing, but thats what he wants. I'm still trying to wrap my head around it. I was … Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Yes, in the past I have seen style guides and standards that deprecate re-using parameter variables,even if the language allows it. I don't know the reason, but maybe its to avoid confusing less-skilled programmers who may think that void fn(int a)… Reply by JamesCherrill
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
> I'm not sure if this is a real world thing If "real world" means "professional C++ programmers", no. > but thats what he wants. What the professor wants, the professor gets! > I'm still trying to wrap my head … Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Appreciat the advice everyone. I'll keep the information in mind. Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
@AssertNull I remember you pointing out that when you inputted a certain value, that the last function in my program would give you an incorrect number. I'm not sure what is going on here to the point that occurs for certain number, but not all. It has … Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Can 't think of why you'd have no issues in Code Blocks. Try entering 2. You get good results from initialcomp_Num? Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
When entered 9, I got a huge number at the end. I was able to see in noMachine this error: g++ -Wall -Wshadow -Wuninitialized -O -o hailstone hailstone.cpp hailstone.cpp: In function ‘int initialcomp_Num(int)’: hailstone.cpp:163:25: … Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
So I gave topValue and initial value of 0. Now the problem seems to be the if statement in the for loop. I have to figure out what to do with the topValue if the initial and cal are equal to one another. The previous function was way easier to deal with. Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
I figured it out. Also, is there a limit to accuracy of the sequence? Reply by Sherwin_4
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Glad you figured it out. To go back to my earlier tips way back... > Every time you assign a new value to top, assign the value that resulted in the sequence of length top to start. Key word is "Every" from "Every time". … Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
> If there are no bugs in your code, it will work everywhere. True for many modern languages, but not C++. C++ suffers from "undefined behaviour" - code situations that the language definition deliberately says are legal but whose … Reply by JamesCherrill
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
I generally take the view that if I code something in a way that can result in "undefined behavior", I have a "bug", though definitions of "bug" vary. Whether C++ "suffers" from undefined behavior or whether that's … Reply by AssertNull
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
Yes, Java is pretty strict on making sure you have initialised variables - and the logic analysis it does to confirm that is pretty sophisticated, but in the end it goes for safety. "No surprises at run time" is a fundamental desire behind Java's… Reply by JamesCherrill
3 Weeks Ago
…> #include <vector> using namespace std; //Function Variable Declaration. int… Discussion Thread by Sherwin_4 in Programming
c++
LOL understood @JamesCherrill Reply by Sherwin_4
3 Weeks Ago
… through array of strings or vector under double quotes and want… <sstream> using namespace std; string GetStdoutFromCommand(string cmd) { string… Discussion Thread by can-mohan in Software Development
1 Week Ago