c++ help with get.line
#include <iostream>; #include <iomanip>; #include <string> #include <cmath> using namespace std; int main() { int yearRate, numbPay; double loan, monthPay, paidBack, interest, rate; cout << setprecision(2) << fixed; //gets loan amount, cout << "Enter the loan amount => "; cin >> loan; //gets yearly interest rate cout <<"Enter the yearly interest rate as a percentage => "; cin >> yearRate; //gets number of payments cout << "Enter the number of payments "; cin >> numbPay; //calculates Monthly Payment, Amount Paid back, and Interest Paid rate = yearRate / 1200.0; monthPay = (( rate * pow((1+rate),numbPay)) / ( pow((1+rate),numbPay) - 1 ) ) * loan; paidBack = monthPay * numbPay; interest = paidBack - loan; //outputs the loan, yearRate, numbPay, monthPay, paidBack, and interest variables cout << "Loan Amount: $ " << loan; cout << "\nYearly Interest Rate: " << yearRate << "%"; cout << "\nNumber of Payments: " << numbPay; cout << "\nMonthly Payment: $ " << monthPay; cout << "\nAmount Paid Back: $ " << paidBack; cout << "\nInterest Rate: $ " << interest; //option to end program cin.ignore(); cout << "\nPress enter to end"; cin.get(); return 0; }
the get.line()works fine and pauses the program until i press enter just fine, unless i use numbers with decimals for the prompts.
This sounds like a bug, but then again, I'm only learning C++ now myself. I tried the code in Codeblocks and if I enter a number with decimals for rate then it won't even let me enter the number of payments.
Join our real-time social learning platform and learn together with your friends!