我最近在学c++,我照着视频上在调一条程序,
#include <iostream.h>
int power (int x, int n);
void main(void)
{
int i;
int value = 0;
char ch;
cout << "Enter an 8 bit binary number";
for(i = 8;i > 0; i--)
{
cin >> ch;
if(ch == '1')
value = value+power(2,i);
else
value += 0;
}
cout <<"Decimal value is" <<value<<endl;
}
int power (int x,int n)
{
int val = 1;
while(n--)
val = val*n;
return(val);
}
但一直不出现应该的结果,希望大家帮着指点一下。 |