Created
January 20, 2019 09:10
-
-
Save NanxingLAI/30e129d243ae1497e58a31fd014588d8 to your computer and use it in GitHub Desktop.
the first task of final exam
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main.cpp | |
// Final_Nanxing_Task1 | |
// | |
// Created by Nanxing LAI on 2019/1/20. | |
// Copyright © 2019 Mac. All rights reserved. | |
// this is the code written in Mac system, I'm not sure whether you can run it successfully in your C++, if not, please let me know it | |
// my email is lainanxing94@163.com. | |
// I will show the table my my coding result. | |
// thank you. Natalia, I learnt a lot from your lectures. | |
#include<iostream> | |
#include<cmath> | |
#include<string> | |
#include<iomanip> | |
using namespace std; | |
//the check of interger number, only for the number of periods | |
int inputInteger(string prompt){ | |
cout << prompt; | |
int n; | |
cin >> n; | |
while(n < 1){ | |
cout << "invalid, " << prompt; | |
cin >> n; | |
} | |
return n; | |
} | |
// the test of double value number, which inluding r, pmt and pv | |
double inputDouble(string prompt){ | |
cout << prompt; | |
double value; | |
cin >> value; | |
while(value < 0){ | |
cout << "invalid, " << prompt; | |
cin >> value; | |
} | |
return value; | |
} | |
int main() | |
{ | |
double r,pv,pmt,a,b; | |
int n; | |
// providing values | |
n = inputInteger("please input number of periods: "); | |
r = inputDouble("please input periodic interest rate: "); | |
pv = inputDouble("please input principal: "); | |
a=pow(1+r,n); | |
b=pv*r; | |
pmt=b*(1+1/(a-1)); | |
cout<<"the pmt is "<<pmt<<endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment