Why is always put out 02?

why is always put out 02 ? Normally the function should just put out 1 because i=0. it just skips the "if" and puts out i(which is really 0) and 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>



using namespace std;

double computeP (int i)
{
if (i=0)
{return 1;}
else
{cout<<i;
return 2;}

}

int main ()
{
cout<<computeP (0);
}

1
2
if(i=0)   // Value of i=0 is 0. Boolean value of 0 is false. This if is always false
if(i==0)  // As should be. 
Last edited on
The reasoning would be because:
= is the assignment operator.
== is the comparison operator.

http://www.cplusplus.com/doc/tutorial/operators/
lol thank you so much. how could i forget about that omg, now i wasted 1hour by searching my mistake and then it's such an easy mistake
Topic archived. No new replies allowed.