Credit Card Interest,余额利息
//Credit Card Interest-余额利息 #include<iostream> int main() { using namespace std; long double balance,rate,tem = 0,sum = 0; int months,i = 0; char ans; do { cout<<"Enter the balance,the rate of month and the month:"; cin>>balance>>rate>>months; while(i < months) { i++; tem = balance * rate; sum += tem; balance = balance + tem; } cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout<<"After "<<months<<" months,the rate is "<<sum<<endl; cout<<"Do you want again?"; cin>>ans; }while('y' == ans || 'Y' == ans); return 0; }
结果:
Enter the balance,the rate of month and the month:1000 0.015 12 After 12 months,the rate is 195.62 Do you want again?y Enter the balance,the rate of month and the month:1000 0.021 12 After 12 months,the rate is 195.62 Do you want again?