Wrong output for loop

This is my output.

50 25 76 38 19 58 29 88 44
22 11 34 17 52 26 13 40 20
10 5 16 8 4 2 1 4 2

This is the output I need, any suggestions?
100 50 25 76 38 19 58 29 88 44
22 11 34 17 52 26 13 40 20 10
5 16 8 4 2 1

int Count_For_Cal;
int Count_For_Output;
int First_Number = 100;
for ( Count_For_Cal = 1; Count_For_Cal <= First_Number ; Count_For_Cal++) {


for ( Count_For_Output = 1; Count_For_Output < 10; Count_For_Output++) {


switch (First_Number % 2)
{
case 0 :
First_Number = First_Number / 2 ;
break;
case 1 :
First_Number = (First_Number * 3) + 1;
break;
default :
break;
}

cout << setw(7) << First_Number;

}

cout << endl;


}
Next time please remember to use the code tags.

The first problem is you need a cout statement for your 100

1
2
3
4
5
6
7
8
 
int Count_For_Cal;
int Count_For_Output;
int First_Number = 100;
cout << First_Number << endl;    //Like so... 
for ( Count_For_Cal = 1; Count_For_Cal <= First_Number ; Count_For_Cal++) 
} 
//and your other stuff...  


The other problem lies in one of your for loops take note that the output you got had an extra value thus suggesting your loop went longer then needed. I am not entirely sure how you worked the logic in these for loops, but my guess the problem is your first for loop due First_Number being constantly changed. I would suggest watching the counter values and ensure they are behaving in the manner you wanted to.
Topic archived. No new replies allowed.