so i have spent 3 hours trying to figure out how exponents work in C++ but now. my if statement isnt working. even if i punch in a 0 it spits out 1
thanks in advance
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
void binToDec(string getBinary);
void main()
{
string getBinary;
cout<<"Enter a Binary Number:"<<endl;
cin>>getBinary;
binToDec(getBinary);
}
void binToDec(string getBinary)
{
int setLength,total=0;
double placeholder=0;
setLength=getBinary.size();
for(int i=setLength;i>0;i--)
{
int num=pow(2.0,placeholder);
int test=getBinary[i];
if (test=1)
{
total=total+num;
}
placeholder=placeholder +1;
cout<<total<<endl;
}
}