| | |
Binary to Decimal HELP :(
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 11
Reputation:
Solved Threads: 0
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
thanks in advance
C++ Syntax (Toggle Plain Text)
#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; } }
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
•
•
•
•
It still won't work. You are comparing char with int:
getBinary[i] is char, and 1 is int.
char != int!!!
Worst case is a compiler warning (eg mismatch of precision of operands). A compiler warning means the programmer should check and make sure the code has the intended result, not that it is disallowed.
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
This thread seems to be predecessor to http://www.daniweb.com/forums/thread150474.html
![]() |
Similar Threads
- Number System:Conversion from binary to decimal (C)
- binary to decimal in c++ code (C++)
- How do I Take in Hexidecimal input out put binary, decimal, and octal (Java)
- i need code for binary to decimal (it should be written in 'C') (C)
Other Threads in the C++ Forum
- Previous Thread: Scanf problem
- Next Thread: Bubble sorting and finding a location of a number in array
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





