标签:bsp 投资 double div += primer float 单利 c++primer
第四题 单利和复利
// 单利投资和复利投资 本金为100元 int count = 1; // 本金 int principal = 100; // A的第一年的收获 float a_alone = principal * 0.1; // B第一年的收获 利息 float b_double = principal * 0.05; // b 收获的总和 float b_Allhavest = b_double; while (b_Allhavest < a_alone * count) { b_double += b_double * 0.05; b_Allhavest += b_double; cout << "b的利息-------" << b_double << endl; count++; } int year = count / 12; int month = count % 12; cout<<"\n\n\n\n\n\n\n\n\n" <<endl; cout << "B的利息" <<b_Allhavest << endl; cout << "A的利息" << a_alone*count << endl; cout << "b的利息" << b_double<< endl; cout <<"经历了" <<year <<"年" <<month <<"月, B的所得利息大于A的利息"<< endl; return 0;
标签:bsp 投资 double div += primer float 单利 c++primer
原文地址:https://www.cnblogs.com/ShacoBlogs/p/9506895.html