I am having trouble making my program output correctly on my 2nd while loop

+2 Giorgio M · September 19, 2015
I am just having issues with this program big time. I have been working on it for 6 days and still no cigar. What's going on is I am trying to do the juggler sequence and I have the calculations correct, the issue I am now having is every time I do the calculations the same number keeps printing and I am having trouble making it output all the numbers on 1 line. If anyone can help that'll be great. Thank you!

This is how the output SHOULD look like but I can't get it.
http://imgur.com/MX6CKhD



#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

using std::cout;
using std::cin;
using std::endl;
using std::setw;


/*
 * 
 */
int main(){
    long user_int = 0;
    long end_int = 0;
    long counter = 0;
    long int_per_line = 0;
    long user_ans = 0;
    
    cout << "Enter two separate numbers, check from low to high " << endl;
    cout << "Input 1st integer: ";
    cin >> user_int;
    cout << "Input 2nd integer: ";
    cin >> end_int;
    
    counter = user_int - 1;
    
    
    long end_start = end_int - user_int;
    
    
    cout << "Do you want to see each sequence (1=yes/0=no):  ";
    cin >> user_ans;
    
    
    while(user_ans == 1){
        for(long i = 0; i <= end_start; i++){
        
            if(user_int % 2 == 0){
                user_int = pow(user_int, 0.5);
                user_int = floor(user_int);
            }
            
            else{
                user_int = pow(user_int, 1.5);
                user_int = floor(user_int);
            }
      
        
            while ( i <= end_start){
                counter = counter + 1;
                if(user_int != 1){
                    cout << "Juggler sequence of " << counter << " is:" << user_int << endl;
                    i = i + 1;
                }
            }
            
        }
        
        
    cout << "Do you want to see each sequence (1=yes/0=no):  ";
    cin >> user_ans;
    

    
    }
    
    
        return 0;
}


Post a Reply

Replies

- page 1
Oldest  Newest  Rating
+2 Milan Obrenovic · September 19, 2015
can you explain what is juggler sequence? how does it work? what is it supposed to achieve? show an example of the input and output of juggler sequence and then i'll try to resolve your problem
+2 Giorgio M · September 19, 2015
Juggler Sequence 

/images/forum/upload/2015-09-19/22bb46cc78ce6efdd5203ff73be29b50.png
+2 Giorgio M · September 19, 2015
What my output should look like
/images/forum/upload/2015-09-19/20a58d57e257bba12af9f697dd60f50f.png
+2 Giorgio M · September 19, 2015
Yes, Say is you entered 10. 10 is even, it will take 10 to the power of (1/2) of (0.5) and it will round it down which would be 3... 3 now is a odd number and it will take 3 to the power of (3/2) or (1.5) and it will round it down which would be 5 after you use the floor function to cut off the decimals. It will keep continuing until it reaches 1.
+1 Milan Obrenovic · September 19, 2015
ahh okay, i understand now (accidentally deleted my above question, sorry).
+1 Giorgio M · September 19, 2015
Can you help me with my output? I ran out of ideas
+1 Milan Obrenovic · September 19, 2015
yes i'm trying now
+2 Milan Obrenovic · September 19, 2015
here you go, done it from scratch:  <removed>

wasn't hard, did it in about 20 minutes. i didn't quite understand what is the "Do you want to see each sequence (1 = yes / 0 = no):" supposed to do but i guess it needs to be in a while loop or something, but anyhow, you can modify it and explore the code
+2 Giorgio M · September 19, 2015
You are the MAN!! I love you so much right now my brain was about to explode.  
+2 Giorgio M · September 19, 2015
Can you give me any resources on how you learn how to code that efficently? I have issues solving the logic of the code
  • 1
  • 2

C++

107,133 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator