User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,799 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,741 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2996 | Replies: 5 | Solved
Reply
Join Date: Oct 2004
Posts: 24
Reputation: cblue is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
cblue cblue is offline Offline
Newbie Poster

Help longest hailstone sequence

  #1  
Nov 19th, 2004
i'm trying to write a program that takes two numbers from the user prints out the sequence between the 2 numbers and then outputs wthe longest sequence

for example if the user inputed 8 and 10

it should out put

8 4 2 1
9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
10 5 16 8 4 2 1

i got the code as follows that does it for 1 number
#include <iostream>
using namespace std;

int f(int n);



int main()
{
int first;
cout << "Enter First Integer: ";
cin >> first;

while(first != 1) //test ithat first is not qual to 1
{
cout << first << " ";


first = f(first);//call function



}
cout << first << endl;

return 0;
}

int f(int n)
{

if(n %2 == 0)//test to see if even
{
return n /=2;

}
else
{
return n = 3*n+1;//is odd

}



}

i need it to do it for two numbers and out but the sequence between those two numbers and then compare them and output that number 9 is the longest sequence it contained 20 numbers any help with this would greatly be appreeciated. forgive me i'm new to the forum and i'm not sure how to use
the code tags.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: longest hailstone sequence

  #2  
Nov 20th, 2004
do you know how to use interpunction?
your ramblings are completely incomprehansible.
Reply With Quote  
Join Date: Oct 2004
Posts: 24
Reputation: cblue is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
cblue cblue is offline Offline
Newbie Poster

Re: longest hailstone sequence

  #3  
Nov 20th, 2004
Here is the code so far now where i'm stuck is how to put the first number into a temp variable call my function and then store the count into a variable and compare the count with the next number called after calling the function.

For example the numbers entered are 8 and 10
after the first call to my function the result is:

8 4 2 1 count = 4

next call

9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 count2 = 20

last call
10 5 16 8 4 2 1 count3 = 7

once i compared the counter i found the longest sewuence out put the longest sequence, i'm stuck as to where to count and then compare the reults here is what i have so far.


Originally Posted by jwenting
do you know how to use interpunction?
your ramblings are completely incomprehansible.
Attached Files
File Type: cpp program6.8pg272.cpp (1.6 KB, 10 views)
Reply With Quote  
Join Date: Oct 2004
Posts: 24
Reputation: cblue is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
cblue cblue is offline Offline
Newbie Poster

Re: longest hailstone sequence

  #4  
Nov 21st, 2004
thanks everyone for your help, i no longer need help with this program, got it all figured out and it's working perfectly.
Reply With Quote  
Join Date: Oct 2006
Location: Idaho
Posts: 44
Reputation: Godfear1 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
Godfear1's Avatar
Godfear1 Godfear1 is offline Offline
Light Poster

Re: longest hailstone sequence

  #5  
Nov 9th, 2006
Could you post your working code for the benifit of the community? Thanks in advance.
Reply With Quote  
Join Date: Jun 2005
Location: Tokyo, Japan
Posts: 1,481
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Rep Power: 8
Solved Threads: 102
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: longest hailstone sequence

  #6  
Nov 9th, 2006
For the benifit of the community could you refrain from digging up threads almost 2 years old ? Thanks in advance.
If you have the same problem please create a new thread with your effort upto now. If you want you can post a link to this thread from your post, so that we know what you are talking about.
バルサミコ酢やっぱいらへんで
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 2:07 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC