mirror of
https://git.hackliberty.org/Awesome-Mirrors/OSSU-computer-science.git
synced 2024-08-21 06:29:00 -06:00
Intro to CS - initial structure problem set 01.02
This commit is contained in:
parent
d8a102b577
commit
0e83b4bad5
@ -45,19 +45,13 @@ prompt.get([
|
|||||||
}
|
}
|
||||||
], function( err, results ) {
|
], function( err, results ) {
|
||||||
|
|
||||||
console.log( results );
|
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
var PERIOD = 12;
|
var PERIOD = 12;
|
||||||
|
|
||||||
// input variables
|
// input variables
|
||||||
var initialBalance = parseFloat( results.balance, 10 );
|
var initialBalance = parseFloat( results.balance );
|
||||||
var interest = parseFloat( results.interest, 10 );
|
var interest = parseFloat( results.interest );
|
||||||
var minPayment = parseFloat( results.minimum, 10 );
|
var minPayment = parseFloat( results.minimum );
|
||||||
|
|
||||||
console.log( initialBalance );
|
|
||||||
console.log( interest );
|
|
||||||
console.log( minPayment );
|
|
||||||
|
|
||||||
// output variables
|
// output variables
|
||||||
var month = 1;
|
var month = 1;
|
||||||
|
@ -5,6 +5,48 @@
|
|||||||
*
|
*
|
||||||
* Paying Debt Off In a Year
|
* Paying Debt Off In a Year
|
||||||
*
|
*
|
||||||
|
* - interest is compounded monthly according to the balance at
|
||||||
|
* the start of the month
|
||||||
|
* - monthly payment must be a multiple of $10 and is the same for all months
|
||||||
|
* - it is possible for the balance to become negative using this scheme
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var prompt = require( 'prompt' );
|
||||||
|
|
||||||
|
prompt.start();
|
||||||
|
prompt.get([
|
||||||
|
{
|
||||||
|
name : 'balance',
|
||||||
|
description : 'Enter the outstanding balance on your credit card'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name : 'interest',
|
||||||
|
description : 'Enter the annual credit card interest rate as a decimal'
|
||||||
|
}
|
||||||
|
], function( err, results ) {
|
||||||
|
|
||||||
|
// constants
|
||||||
|
var PERIOD = 12;
|
||||||
|
|
||||||
|
// input variables
|
||||||
|
var initialBalance = parseFloat( results.balance );
|
||||||
|
var interest = parseFloat( results.interest );
|
||||||
|
|
||||||
|
// helper variables
|
||||||
|
var monthPayment = 0;
|
||||||
|
var monthsNeeded = 0;
|
||||||
|
var totalBalance = initialBalance;
|
||||||
|
var monthInterest = interest / 12;
|
||||||
|
|
||||||
|
while ( totalBalance > 0 ) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log( '======= RESULT =======');
|
||||||
|
console.log( 'Monthly payment to pay off debt in 1 year:' );
|
||||||
|
console.log( 'Number of months needed:' );
|
||||||
|
console.log( 'Balance' );
|
||||||
|
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user