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

新手请教,关于定义float出现的警告信息.

kknan 发布于 2010-04-22 04:12, 573 次点击
#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, char* argv[])
{
    float i = 1000.0 ,r = 0.05,a=0.0,b=0.0;
    for(int j =1 ;j<=10;j++)
    {
        a = i * r;   //利息
        i = i + a;   //本金+利息
        b+=i;        //总额
        cout<<"第"<<j<<"年的本金加利息是:"<<i<<endl;
    }
    cout<<j-1<<"年的总金额为:"<<b;
    return 0;
}

以上代码在vc6编译通过且可以运行.
但是提示以下警告:
warning C4305: 'initializing' : truncation from 'const double' to 'float'
是不是我在定义变量的时候出了什么问题呢?
2 回复
#2
cnfarer2010-04-22 06:15
float i=100.0f;
#3
kknan2010-04-22 14:17
- - 知道了,已经改正,谢谢了.
1