注册 登录
编程论坛 C++教室

请老师看看我的磅转化成千克的程序错在哪里,谢谢

新手45656 发布于 2012-03-24 10:44, 915 次点击
#include <iostream>
using namespace std;
   
int main()
{
    const float KG_PER_POUND=0.454;
    float pounds,
        kgs;
    cout<<"Enter the weight in pounds:";
    cin>>pounds;
    float   kgs=KG_PER_POUND*poundS;
    cout<<"The weight in kilograms is"<<kgs<<endl;
    renturn 0;
}   
6 回复
#2
hellovfp2012-03-24 11:00
#include <iostream>
using namespace std;
   
int main()
{
    const float KG_PER_POUND=0.454f;
    float pounds, kgs;

    cout<<"Enter the weight in pounds:";
    cin>>pounds;
    kgs = KG_PER_POUND * pounds; //这里重复定义kgs, pounds打错了
    cout<<"The weight in kilograms is"<< kgs << endl;

    return 0; //return打错了。
}
#3
新手456562012-03-24 11:08
回复 2楼 hellovfp
  kgs = KG_PER_POUND * pounds; //这里重复定义kgs, pounds打错了
这句删掉吗?我删了还不行。你能给我说应怎么改好吗?谢谢了
#4
hellovfp2012-03-24 11:12
上面是改好的程序,你自己对照着看有哪些地方不同吧。
#5
新手456562012-03-24 11:21
回复 4楼 hellovfp
编译器说有错误,要把程序改成cpp格式,怎么改呀?
#6
新手456562012-03-24 11:35
弄好了,谢谢你,请问const float KG_PER_POUND=0.454f;为什么加f?
#7
pangding2012-03-25 08:29
因为默认的小数是 double 的,0.454f 后面的 f 是告诉编译器这个数是 float。
一般来说 float 使用的频率非常之低,没有特殊需要最好是使用 double。
1