error in writing a simple Collatz conjecture code C++

Viewed 28

this is my code:

#include <cmath>
using namespace std;

int main() {
int n;
cout << "Enter an integer: ";
cin >> n;
  while ( n != 0){
    if ( n % 2 == 0)
        cout << n << n;
        (n == n / 2);
    else
        cout << n << n;
        (n == n * 3 + 1);
  }
return 0;
} 

but when i try to run it i get this error:

mene.cpp:13:5: error: ‘else’ without a previous ‘if’
   13 |     else
      |     ^~~~

i do have some experience with python but just started with c++ today. any help would be much appreciated

0 Answers
Related