为什么输出是inf?

#include using namespace std;

class counter

{public:

counter(int n,int q,float p) : num (n),quantity (q) , price(p) { }

void total ( )

{

sum+= quantity*price ;

count+= n ;

}

static float average ( )

{return (sum/count) ;}

static void display( )

{cout<

private:

int num ;

int quantity ;

float price ;

static float sum ;

static int n ;

static int count ;};

float counter:: sum = 0 ;

int counter:: n = 0 ;

int counter:: count=0;

int main ( )

{

counter c[ 3 ] ={ counter ( 101 , 5 , 23.5 ) , counter ( 102 , 12 , 24.56 ) , counter ( 103 , 100 , 21.5 ) };

for ( int i=0 ; i<3 ; i++ )

c [ i ] . total ( ) ;

counter::display();

return 0 ;

}

101,5,23.5分别是编号,件数和单价。我想输出三个对象的平均价格,也就是523.5+1224.56+100*21.5再除以5+12+100。不知道为什么会显示超出范围,问题出在哪呢?先谢谢大家了!

大陆将来可以邀台湾一起申办世界杯
英国Harrods百货购物指南(直邮中国+退税)
Copyright © 2022 2018世界杯时间_世界杯百大球星 - gonhee.com All Rights Reserved.