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
+1 Giorgio M · September 19, 2015
That helps, Thanks Milan!
+1 Milan Obrenovic · September 19, 2015
i cant, the link will exist forever. i can only edit my comment to delete the link there, if it helps?
+1 Giorgio M · September 19, 2015
Hey Milan, if you don't mind, is it alright if you could delete that pastebin file? Thank you again
+2 Giorgio M · September 19, 2015
Thank you Milan!
+2 Milan Obrenovic · September 19, 2015
i don't know a lot of books but i bought this one long time ago:  https://goo.gl/dDircA

it explains everything from scratch with tasks, examples, and solutions. i think it also gives you ability to try some examples to solve by yourself, and if you can't do it, it has a solution written in code, so you can check it out.
+2 Giorgio M · September 19, 2015
Thanks so much, any resources or books you can let me know about though?
+2 Milan Obrenovic · September 19, 2015
to be honest, making algorithms is my weakest side of the programming. the way i learned making them was all thanks to school. our teacher gave us tasks to practice in c++ so we can be prepared for the competition. the tasks he gave us were ffffffffffucking hard as hell that your problem is nothing compared to what we had to solve. and if you're wondering, no, i'm not yet in college. this is actually a perfect opportunity for us to carry additional knowledge of creating algorithms once we start college.

edit:

by the way, to make your code more efficient and faster, instead of cout  and cin, use fscan and fprint functions, because they do the work twice as faster, and don't forget to include <cstdio> and <cstdlib> at the top, if you're using those functions.
+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
+2 Giorgio M · September 19, 2015
You are the MAN!! I love you so much right now my brain was about to explode.  
+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
  • 1
  • 2

C++

107,093 followers
About

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

Links
Moderators
Bucky Roberts Administrator