Hello!
I'm just starting to learn C++ for school, and our first assignment is creating a series of numbers according to the following rule:
current value next value
1 none - the sequence terminates
even current / 2
odd 3*current + 1
I have to compute for the initial values 1-60. My task is to count the length o the series for each of the initial values, so the outcome should be:
series length number of occurences
1 1
2 1
3 1
4 1
5 1
6 2
7 1
8 3
9 3
...
40 0
so far, my code is :
// SeriesLength.h
#pragma once
using namespace System;
namespace SeriesLength {
int count = 0;
int series(int seed){
if (seed == 1){
count ++;
return count;
}
if (seed == 2 || seed == 4 || seed == 6 || seed == 8 || seed == 10|| seed == 12 || seed == 14 || seed == 16){
seed = seed / 2;
count ++;
}
else{
seed = seed * 3 + 1;
count ++;
}
series(seed);
return count;
}
int main(){
const int MAX_NUM = 4;
const int MAX_CALLS = 41;
int num_calls[MAX_CALLS];
//int length = 0;
//int occurences = 0;
cout << "series length \t number of occurences";
for (int i = 0; i < MAX_NUM; i++){
//cout << length << occurences;
num_calls[i]++;
}
for (int i = 0; i < MAX_NUM; i++){
//cout << length << occurences;
cout << num_calls[i];
}
return 1;
}
}
however, the compiler's complaining about my 'cout' and i don't know what to do...help would be GREATLY appreciated, as this assignment is due tomorrow.
thanks!
Hong