The program can be executed but the fragments of code is wrong especially the calculation part. By the way, it is about to convert the binary to decimal. Please helpppp
#include <iostream>
#include <cmath>
#include <cstdlib> // this should be #include <string>
usingnamespace std;
int main ( )
{
// more descriptive variable names would be good. f is never used.
int binary, rem, MyEnd, i, c, f, num;
string bin;
cout << "Please enter the binary number\n";
cin >> binary;
// It isn't necessary to enter the number twice.
cout << "Please re-enter the binary number\n";
// strings can be assigned int values
// like this: bin = binary;
cin >> bin;
for ( num = binary; num <= 0; --num )
num /= 10;
rem = num % 10;
// If you set i to 0, and never decrement it, it will never be negative.
// There's no reason to check for that.
for ( i = 0; i >= 0 && i < bin.size ( ); ++i )
if ( !rem || rem == 1 )
c = rem + ( 2^i ); // 2^i does not do what you think it does.
// To take a number to a power, you have to use the pow function.
// Like this: pow ( 2, i );
c = c + 0; // this line does nothing
cout << "The binary that converted into decimal is" << c << '\n';
// There is a better way to do this without using a variable.
cout << "Press any integer number to continue\n";
// Use cin.ignore ( );
cin >> MyEnd;
}
That message makes no sense. Please quote the EXACT error message.
You're probably going to get a warning on the following line that you're trying to assign a double to an int. c=rem + pow((double)2,i);
Pay attention to what C or C++ version you're using.
pow with a double and a a float is only supported in C++11, although C++98 should convert the float to a double. C does not support a double and an float as arguments. http://www.cplusplus.com/reference/cmath/pow/
@OP: when you say `pow' you are referring to the variable that you declared with double pow;
So `(the variable) pow (of type double) cannot be used as function'
To refer to the function use std::pow (or don't go colliding names and remove the variable declaration, that you are not using at all)