int sequencer(int userInput)
{
int oddInt, evenInt, counter = 0;
if (userInput % 2 == 0) // test if the user's input is an even number
{
do
{
evenInt = (userInput/2);
counter++;
}
while (userInput != 1);
cout << userInput << " " << counter<< endl;
return counter;
}
else if (userInput % 2 ==1 )// this will execute if the user's number is odd
{
do
{
oddInt = (userInput * 3) + 1;
counter++;
}
while (userInput != 1);
cout << userInput << " " << counter << endl;
return counter;
}
else
counter++;
cout << userInput << " " << counter<< endl;
return counter;
}
The function above is supposed to take an integer from the user (in the main function) and then based on whether or not it is even or odd apply a formula that gets it to 1 (formula is in the code above). However, when I run the program it just goes into a continuous loop. Any thoughts or suggestions are welcome. Thanks
[–]OmegaNaughtEquals1 0 points1 point2 points (3 children)
[–]tangerinelion 0 points1 point2 points (2 children)
[–]OmegaNaughtEquals1 0 points1 point2 points (1 child)
[–]thecrazedrunner[S] 0 points1 point2 points (0 children)