diff --git a/computer-science/01-introduction-to-cs-and-programming-mit/src/01-01-problem-set.js b/computer-science/01-introduction-to-cs-and-programming-mit/src/01-01-problem-set.js index c78e00a..5e3f9d4 100644 --- a/computer-science/01-introduction-to-cs-and-programming-mit/src/01-01-problem-set.js +++ b/computer-science/01-introduction-to-cs-and-programming-mit/src/01-01-problem-set.js @@ -45,20 +45,14 @@ prompt.get([ } ], function( err, results ) { - console.log( results ); - // constants var PERIOD = 12; // input variables - var initialBalance = parseFloat( results.balance, 10 ); - var interest = parseFloat( results.interest, 10 ); - var minPayment = parseFloat( results.minimum, 10 ); + var initialBalance = parseFloat( results.balance ); + var interest = parseFloat( results.interest ); + var minPayment = parseFloat( results.minimum ); - console.log( initialBalance ); - console.log( interest ); - console.log( minPayment ); - // output variables var month = 1; var minMonthlyPayment = 0; diff --git a/computer-science/01-introduction-to-cs-and-programming-mit/src/01-02-problem-set.js b/computer-science/01-introduction-to-cs-and-programming-mit/src/01-02-problem-set.js index 19fab35..55a2f46 100644 --- a/computer-science/01-introduction-to-cs-and-programming-mit/src/01-02-problem-set.js +++ b/computer-science/01-introduction-to-cs-and-programming-mit/src/01-02-problem-set.js @@ -5,6 +5,48 @@ * * 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' ); + +});