I wanted am a beginner, and wrote this code as part of a project. Depending on the loanCode, I wanted to set different values to variables and print them out. However, The program is just ignoring the initializations in the "if" clauses. Anyone know what's wrong? Thanks!
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
cout << "This program can be used for new and existing loans!" << endl;
int loanLength;
int paymentPerYear;
double interestRate;
int maxAmount;
int minAmount;
string borrowerName;
cout << "Please enter the borrower's full name: " << endl;
getline (cin,borrowerName);
int loanCode;
cout << "Please enter a BRSL loan code: " << endl;
cin >> loanCode;
if (loanCode == 10)
{
int loanLength = 30; // (30-year plan)
int paymentPerYear = 12; // (12 payments per year)
double interestRate = .038; // (Interest Rate is 3.8%)
int maxAmount = 425000; // (Maximum amount is $425000)
int minAmount = 5000; // (Minimum amount is 5000)
cout << "ok 10" << endl;
}
else if (loanCode == 20)
{
int loanLength = 15; // (15-year plan)
int paymentPerYear = 12; // (12 payments per year)
double interestRate = .029; // (Interest Rate is 2.9%)
int maxAmount = 425000; // (Maximum amount is $425000)
int minAmount = 5000; // (Minimum amount is 5000)
cout << "ok 20" << endl;
}
else if (loanCode == 30)
{
int loanLength = 5; // (5-year plan)
int paymentPerYear = 12; // (12 payments per year)
double interestRate = .026; // (Interest Rate is 2.6%)
int maxAmount = 100000; // (Maximum amount is $100000)
int minAmount = 5000; // (Minimum amount is 5000)
cout << "ok 30" << endl;
}
else if (loanCode == 40)
{
int loanLength = 2; // (2-year plan)
int paymentPerYear = 12; // (12 payments per year)
double interestRate = .072; // (Interest Rate is 7.2%)
int maxAmount = 25000; // (Maximum amount is $25000)
int minAmount = 500; // (Minimum amount is 500)
cout << "ok 40" << endl;
}
else
{
cout << "Loan code is not a valid value." << endl;
cout << "Program will exit now" << endl;
return 0;
}
cout << "your loan code is: " << loanCode << endl;
cout << "loanLength: " << loanLength << endl;
cout << "paymentPerYear: " << paymentPerYear << endl;
cout << "interestRate: " << interestRate << endl;
cout << "maxAmout: " << maxAmount << endl;
cout << "minAmount: " << minAmount << endl;
return 0;
}
OUTPUT:
This program can be used for new and existing loans!
Please enter the borrower's full name:
Joe Shmoe
Please enter a BRSL loan code:
10
ok 10
your loan code is: 10
loanLength: 0
paymentPerYear: 0
interestRate: 0
maxAmout: 0
minAmount: 0
Program ended with exit code: 0
Aucun commentaire:
Enregistrer un commentaire