以下程序VC編譯成功,完全符合妳的要求
不過對輸入的購買金額有點要求,最好不要上億。過這個坎,我就不保證能正確了。
#include<stdio.h>
#define Week 7
#define Mz 1 //設置基金的面值
#define SGfl 0.015 //設置申購費率
#define SHfl 0.005 //設置贖回費率
unsigned long cash; //購買金額
unsigned long quotient;//份額
float Netv[Week+1]; //每日凈值
float avNet;//平均凈值
void inquotient()//要求輸入購買金額,並求得份額
{
int Right=0;
while(!Right)
{
printf("Please input your money(=>1000, and multiple):");
scanf("%ld",&cash);
if(cash % 1000==0) Right=1;
quotient=(long)(((float)cash-SGfl*(float)cash)/Mz);
}
}
void inNet()//要求輸入每日凈值,最後壹個值為0,表示輸入結束
{
int i;
Netv[0]=0;
printf("Please input everyday net value in this week: \n");
for(i=1;i<=Week;i++)
{
scanf("%f",&Netv[i]);
if(Netv[i]!=0) Netv[0]++;
else break;
}
}
main()
{
int i;
long CV,CP;//Current valuer ,Current Payoff,
float InR,sum=0;//increase Rate
inquotient();
inNet();
printf("Quotient Net Value Increase Rate Current Value Current Payoff\n");
for(i=1;i<=Netv[0];i++)
{
sum+=Netv[i];
if(i==1){ InR=(float)(Netv[i]-1)*100;}
else{
InR=Netv[i]-Netv[i-1];
InR=InR/Netv[i-1];
InR*=100;
}
CV=quotient*Netv[i];
CP=(long)(1-SHfl)*CV-cash;
printf("%ld %10.5f %11.2f%% %10d %10d\n",quotient,Netv[i],InR,CV,CP);
}
avNet=sum/Netv[0];
printf("Average Net Value in this week = %f %6.5f\n",sum,avNet);
}