Syntax error, maybe a missing right parenthesis
in
Programming Questions
•
5 months ago
Hi! I have a problem with my second tab...I have no idea what I am missing. I'm also trying to use loop and create a graph that displays the result of the collatz value. Please help! Any corrections are welcome. Thank you!
First tab
final int WIDTH = 300;
final int HEIGHT = 300;
void setup() {
size(WIDTH, HEIGHT);
background(0);
print(collatzValue(2));
print(", ");
print(collatzValue(6));
print(", ");
print(collatzValue(10));
print(", ");
print(collatzValue(25));
print(", ");
print(collatzValue(32));
print(", ");
print(collatzValue(42));
}
void draw() {
}
Second tab
/*
returns the number of operations*
it takes to reduce that number to one.
the operations are -
if number even, number is divided by 2
otherwise, number is multiplied by 3
and 1 is added to it.
For example, if n = 10
10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1
6 operations, hence function returns 6
*/
int n;
int collatzValue(int n) {
for (int n = 5; n <10000 ; n++){
if(n=2; n<1000; n++){
n/=2;
total ++;
}
}
else {
n = 3*n+1;
total ++;
}
}
1