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

大家再帮我改下错!!!

flysky102 发布于 2008-03-05 20:27, 1494 次点击
下面程序Daphne和Cleo分别是两个人,程序目的是,D是以10%的单利投资投资了100元既:利息=0.1*原始存款,C是以5%的复利投资投资了100元,也就是第一年赢利105。第2年赢利是105的5%=5.25,写的时候也感觉不对,可是也不知道错在哪了
#include <iostream>
const int Daphne=100;
const int Cleo=100;
int main()
{using namespace std;
 int daphnes;
 daphnes=Daphne*0.1;
 int cleos;
 cleos=Cleo*0.05;
 int year=1;
 for(year;cleos<=daphnes;year++)
 {cleos=(Cleo+cleos)*0.05;
  year++;
}
 cout<<year<<endl;
 system("pause");
 return 0;
}
10 回复
#2
lonmaor2008-03-05 20:39
Daphne第n年的总价值应该是100*10%*n+100;
Cleos第n年的总价值应该是100*(1+5%)^n;
#3
flysky1022008-03-05 20:46
懂是懂什么意思了,可是写程序时感到很茫然,刚才试写了下,结果发现程序还是不对:
# include <iostream>
const int Daphne=100;
const int Cleo=100;
int main()
{using namespace std;
 
 int year=1;
 for(year;Cleo*(1+0.05)^year=Daphne*0.1*year+100;year++)
 {cleos=(Cleo+cleos)*0.05;
  year++;
}
 cout<<year<<endl;
 system("pause");
 return 0;
}
#4
lonmaor2008-03-05 20:51
Try this:
程序代码:

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

const int Daphne=100;
const int Cleo=100;

int main()
{
    double daphnes=Daphne,cleos=Cleo;
    int year;
    for (year=1; cleos<=daphnes; ++year)
    {
        daphnes += Daphne*0.1;
        cleos *= 1.05;
        cout<<year<<" year\t"<<"Daphne:"<<daphnes<<"\tCleo:"<<cleos<<endl;
    }
    system("pause");
    return 0;
}


[[it] 本帖最后由 lonmaor 于 2008-3-5 20:52 编辑 [/it]]
#5
flysky1022008-03-05 21:25
#include <iostream>
#include <cstdlib>   //这个是什么头文件?我是初学,不要见笑
#include <cstring>
using namespace std;

const int Daphne=100;
const int Cleo=100;

int main()
{
    double daphnes=Daphne,cleos=Cleo;
    int year;
    for (year=1; cleos<=daphnes; ++year)
    {
        daphnes += Daphne*0.1;
        cleos *= 1.05;
        cout<<year<<" year\t"<<"Daphne:"<<daphnes<<"\tCleo:"<<cleos<<endl;
    }
    system("pause");
    return 0;
}
#6
tszhao2008-03-05 21:33
楼主的代码看起来没有语法上的错误,但是,一个很低级的错误就是出现在for循环里,循环没有办法结束,你的代码是  cleos=(Cleo+cleos)*0.05;
而应该改成cleos=(Cleo+cleos)*(1+0.05);
#7
emmc2008-03-06 13:46
看看
#include <iostream>
using namespace std;
const int Daphne=100;
const int Cleo=100;
int main()
{
   
   double daphnes=Daphne*0.1;
   int cleos;
       cleos=Cleo*0.05;
   int year=1;
  for(year;cleos<=daphnes;year++)
  {   
      daphnes = daphnes*.1 + 100;
      cleos = (Cleo+cleos)*(0.05+1);
      year++;
  }
  cout<<"year = "<<year<<endl;
  cout<<"daphnes = "<<daphnes<<endl<<"cleos = "<<cleos<<endl;
  system("pause");//这一个我没有学过呢?是什么呀?我也中刚学VC++的一个新手吧
  return 0;
}
#8
flysky1022008-03-07 13:17
system("pause");//这个是让系统等一等的,叫什么名字我也不知道,我也是从别人那学的我的编程是自学的,如果没这个你会看不到结果的
#9
lonmaor2008-03-07 14:04
cstdlib对应于C中的<stdlib.h>
顾名思义,包含了大量的标准库函数.
因为使用了system(),故需要包含之。
pause是一条dos命令。这里通过system()调用它使程序暂停一下。
#10
zhangdezhao2008-03-07 16:57
帮你改
你那个很明显啊  多了个year++啊  for(year;cleos<=daphnes;year++——————————这儿有一个了,下边就不用了啊)
  {   
      daphnes = daphnes*.1 + 100;
      cleos = (Cleo+cleos)*(0.05+1);
      year++;
#11
a198705022008-03-08 18:36
题目的意思是不是问:多少年后,C的赢利开始大于D?
1