#include<iostream>
#include<cmath>
using namespace std;
main()
{
int deci, rem, octal=0, i=1;
float de, x,y,point,rem1;
cout<<"enter the decimal"<<endl;
cin>>deci;
deci=y;
de=y-deci;
while(deci!=0)
{
rem= deci % 8;
deci=deci / 8;
octal+=rem*i;
i=i*10;
}
while (de!=0)
{
point=de * 8;
}
cout<<"the octal is "<<octal<<"."<<point<<endl;
}
当我输入12.5时,它应该给我14.4,但不是显示14.0,而是根据逻辑,根据int和float,应将y视为12.5,将deci视为12,但它将两者都视为12.5 ... < / p>
答案 0 :(得分:0)
int deci, rem, octal=0, i=1;
float de, x,y,point,rem1;
cout<<"enter the decimal"<<endl;
cin>>deci;
由于deci
被声明为int
cin>>deci
,输入'12 .5'会将deci
设置为12
顺便说一句,我假设下一行是抄写错误deci=y
根本没有任何意义。我想你是说y = deci
解决方案-将deci声明为浮点数;