I think I'm getting myself more confused. How do I take those numbers and actually make it work?
Originally Posted by whiteflags
I've been on this all night and haven't gotten anywhere.
Here is the code I have and the problem with it.
So in this code I wrote it will convert any binary number to decimal, however the problem is the user has to put the binary number in 1 number at a time, with either a space or enter.
using namespace std;
int binary1, binary2, binary3, binary4, decimal1, decimal2, decimal3, decimal4, total;
cout << "Enter a 4-digit binary number: " ;
cin >> binary1 >> binary2 >> binary3 >> binary4;
decimal1 = binary4 * 1;
decimal2 = binary3 * 2;
decimal3 = binary2 * 4;
decimal4 = binary1 * 8;
total = decimal1 + decimal2 + decimal3 + decimal4;
cout << "The decimal equivalent of " << binary4 << binary3 << binary2 << binary1 << " is " << total << endl;
I don't know how to do the calculation with just one statement. So the user could just enter the number as one number, instead of 4.