I'm having a problem checking for invalid binary inputs from the user. Here is the program. Can anyone tell me how to approach this?
These are the errors I'm getting
error C2660: 'binToDec' : function does not take 1 arguments
warning C4018: '<' : signed/unsigned mismatch
error C2082: redefinition of formal parameter 'bin'
error C2275: 'std::string' : illegal use of this type as an expression
see declaration of 'std::string'
error C2082: redefinition of formal parameter 'bin'
#include<iostream>
#include<string>
usingnamespace std;
void binToDec(); // A. declaration of function prototype
int main()
{
string bin;
binToDec(bin); // B. call the function
return 0;
}
void binToDec(string bin) // C. definition of function
{
// The actual code for the function goes here
}
Both A and C must have the same return type (void in this case), all three of A, B and C must have the same number and type of parameters. Here B and C agree, but declaration A specifies the function takes no parameters at all.
Below, the function string getBin() is receiving a string as an input parameter, and then immediately attempts to define another, different string with the same name. In this case the answer is to remove the input parameter. The return statement should give the name of the variable (bin) but instead gives its type (string).
Function binToDec() has a similar problem with a parameter passed to the function followed by a different variable with the same name. In this case the answer is to keep the input parameter, but remove the extra variable.