My objective is to calculate and output a loan repayment schedule. The thing I would like to get help on is putting the principles added to the equation and printing out the repayment schedule. I am not sure if I did the calculations right as I have not had a personal finance class yet, and still get to grasp the concept of loans.
The loan repayment schedule is based on full price of an auto, their interest rate and their payment, assuming no money is put down. All fees and taxes are included in the price and will be financed. I also have to out put the repayment schedule to both the screen and a file - one month per line. . If the user has a credit rate of 800, they get a 3% annual interest rate; 700+ gets 5% interest rate; 600+ get 7% interest rate; and less than 600 get 12% interest rate
The credit scores for 700, 600, and below 600 are left blank because I am just going to copy the 800 credit score part again but change the interest rates.
// This program calculates a loan depending on the pereson's credit score
// how much they can pay per month. It almost outputs the month, principal,
// payment, interest, and the money that's been applied
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
int main() {
int month = 0, creditScore = 0, whichCar;
double principle, payment = 0.0, interestPaid, applied, interestRate;
cout << fixed << setprecision(2) << showpoint; // Sets total or whatever to 2 decimal points
cout << "---------------------------------------------" << endl; // Displays welcome banner
cout << "| |" << endl;
cout << "| JOLLY GOOD SHOW WE HAVE CARS AYEEE |" << endl;
cout << "| |" << endl;
cout << "---------------------------------------------" << endl;
cout << endl;
cout << "Hey, I see you want a car. You can only purchase one car though." << endl;
cout << endl;
cout << "1. Furawree: $6,969.69" << endl; // Displays menu of autos
cout << "2. Buggee: $420,420.420" << endl;
cout << "3. Sedon: $900" << endl;
cout << "4. Truck: $900,000.90" << endl;
cout << "5. Couppee: $22,222.22" << endl;
cout << endl;
cout << "Which car would you like to purchase?" << endl; // Asks user car type and user inputs car #
cout << "Please enter the number of the car: ";
cin >> whichCar;
cout << endl;
switch(whichCar) { // If user choses a number 1-5, then it asks them how much they can pay each month for the car and their credit score
case 1: // FURAWREE
principle = 6969.69;
break;
case 2: // BUGGEE
principle = 420420.42;
break;
case 3: // SEDON
principle = 900;
break;
case 4: // TRUCK
principle = 900000.90;
break;
case 5: // COUPPEE
principle = 22222.22;
break;
default: // If user doesn't pick a number from 1-5
cout << "Yea uhhmmm we don't have that sorry, go away." << endl;
}
cout << "Please enter how much you can pay each month for this Furawree: ";
cin >> payment;
cout << "Please enter your credit score: ";
cin >> creditScore;
if (creditScore >= 800) {
interestRate = .03 / 12;
do {
interestPaid = principle * interestRate;
applied = payment - interestPaid;
month++;
} while (principle < 0) ;
cout << "Month " << " Principle " << " Payment " << " Interest " << " Applied " << endl;
cout << month << " $" << principle << " $" << payment << " " << interestPaid << " $" << applied << endl;
} else if (creditScore >= 700) {
// Will be copied from the 800 credit score
} else if (creditScore >= 600) {
// Will be copied from the 800 credit score
} else {
// Will be copied from the 800 credit score
}
cout << endl;
cout << endl;
cout << "Your payment: $" << payment << endl;
cout << "Your credit score: " << creditScore << endl;
cout << endl;
cout << endl;
system("pause");
return 0;
}
Mate, you need to fix code under credit - 800.
loop condition is incorrect
cout is after the loop, therefore it will print only once .
principle is not incremented nor decremented . and you are checking if principle is less than 0, however principle is set more than 0. so the loop will execute only once.
you need a fix some thing like this. I have just fine tuned little bit. pls fix the rest
if (creditScore >= 800) {
interestRate = .03 / 12;
cout << "Month " << " Principle " << " Payment " << " Interest " << " Applied " << endl;
cout <<"-------------------------------------------------------" << endl;
do {
interestPaid = principle * interestRate;
applied = payment - interestPaid;
principle = principle - applied;
cout << month << " $" << principle << " $" << payment << " " << interestPaid << " $" << applied << endl;
month++;
} while (principle > 0) ;
} else if (creditScore >= 700) {
Note :-
The above code is not following any object oriented concepts. Its not even functional programming. Introduce classes, methods to reduce headache and it will help to debug.
use \t\t to get spaces instead of spaces.
This code will need a big re-work to make it look professional .
Related
For a project I have to write an application that calculates the price of gas. The code works great, but I noticed something that will probably get points deducted. My total price doesn't include a dollar sign. I am stuck on where to add them and how. Below is my code. Please help!
// FinalProject1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
using namespace std;
const double PRICE_OF_REGULAR = 1.67;
const double PRICE_OF_SPECIAL = 1.87;
const double PRICE_OF_SUPER = 1.99;
int main()
{
cout << "Gas Pump Calculator!" << endl;
double numberOfGallons;
cout << "Please enter number of gallons needed: ";
cin >> numberOfGallons;
cout << endl;
cout << "1. Regular" << endl;
cout << "2. Special" << endl;
cout << "3. Super+" << endl;
cout << endl;
int choice;
cin >> choice;
switch (choice)
{
case 1:
cout << endl;
cout << "You chose regular. The total price of gas is: " << (numberOfGallons * PRICE_OF_REGULAR);
cout << endl;
break;
case 2:
cout << endl;
cout << "You chose special. The total price of gas is: " << (numberOfGallons * PRICE_OF_SPECIAL);
cout << endl;
break;
case 3:
cout << endl;
cout << "You chose super+. The total price of gas is: " << (numberOfGallons * PRICE_OF_SUPER);
cout << endl;
break;
}
return 0;
}
Just print a dollar sign after the number:
cout << "You chose regular. The total price of gas is: "
<< (numberOfGallons * PRICE_OF_REGULAR) << "$";
//^ add dollar sign
Or before the number, depending on how you want to print it out.
cout << "You chose regular. The total price of gas is: $"
<< (numberOfGallons * PRICE_OF_REGULAR); //^ add dollar sign
Just add it before your value:
cout << "You chose regular. The total price of gas is: $"
<< (numberOfGallons * PRICE_OF_REGULAR);
So i am very new to programming and C++. This little simple program is my second one and I'm in need of a little assistance. Below is my code followed by the output that I am getting and what I want it to look like. If anyone can point me in the right direction, or let me know how to change this it would be much appreciated.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
double propValue, //Property Value
assessment, //Assessment
srAssessment, //Sr Assessment
taxRate, //Tax rate
annualPropTax, //Annual Property tax
quarterlyTax; //Quarterly Tax
string name;
const double EXEMPT = 5000, //shows the total after exemption
QUARTER = 4, //represents the amount of quarters in a year
TAXPERHUNDRED = 0.01, //represents tax rate for every $100
SIXTYPERCENT = 0.6; //Represents the tax based on 60% of original value
//Gets name from user
cout << "Please enter your full name: ";
getline(cin, name);
//gets property value from user
cout << "Enter the actual value of the property: ";
cin >> propValue;
//Gets tax rate
cout << "Enter the tax rate for each $100 of assessed value: ";
cin >> taxRate;
cout << endl << endl;
//Calculates assessment
assessment = propValue * SIXTYPERCENT;
//Calculates Sr. Assessment
srAssessment = assessment - EXEMPT;
//Calculates annual property tax
annualPropTax = srAssessment * taxRate * TAXPERHUNDRED;
//Calculates Quarterly tax
quarterlyTax = annualPropTax / QUARTER;
//Displays owners name
cout << "Property owner's name: " << name << endl;
cout << endl;
cout << setprecision(2) << fixed;
//Displays Assesment
cout << "Assessment: " << setw(18) << "$ " << srAssessment << endl;
//Displays Annual Property tax
cout << "Annual Property Tax" << setw(11) << "$ " << std::right << annualPropTax << endl;
//Displays Quarterly Property tax
cout << "Quarterly Property Tax" << setw(8) << "$ " << std::left << quarterlyTax;
cout << endl << endl;
}
This is the current output:
Assessment: $ 175000.00
Annual Property Tax $ 7177.50
Quarterly Property Tax $ 1780.63
What I need it to do is display as so:
Assessment: $ 175000.00
Annual Property Tax $ 7177.50
Quarterly Property Tax $ 1780.63
I guess it should be intutive. Add setw to second print also:
cout << "Assessment: " << setw(18) << "$ " << setw(10) << std::right << srAssessment << endl;
// ^^^^^^^^^^^^^^^^^^^^^^^^^
cout << "Annual Property Tax" << setw(11) << "$ " << setw(10) << std::right << annualPropTax << endl;
// ^^^^^^^^^^^
cout << "Quarterly Property Tax" << setw(8) << "$ " << setw(10) << std::right << quarterlyTax;
// ^^^^^^^^^^^^^^^^^^^^^^^^^
Add right in your cout statement
Here is another stack overflow post related:
Right Justifying output stream in C++
std::cout << std::right << std::setw(x) << "output";
Where x is an integer to represent the width of the following "output".
I'm new to C++ and development in general. Frankly, I have no idea what is going on. I'm just trying to display a string on one line, but the program is giving me a confusing error.
I would really appreciate any help.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// This program calculates and displays to user
int main()
{
// Constants are state and county taxes.
const float STATE_TAX_RATE = 0.04,
COUNTY_TAX_RATE = 0.02;
// float variables are :
float gross_sales = 0,
net_sales = 0,
county_tax_payment = 0,
state_tax_payment = 0,
total_tax_payment = 0;
// string variable
string month;
// integer variable
int year;
// Get month, year, and sales information from user
cout << "For what month is this? (Please type the name of the month.)\nAnswer: ";
getline(cin, month);
cout << "For what year?\nAnswer: ";
cin >> year;
cout << "How much was total sales at the register?\nAnswer: ";
cin >> gross_sales;
// Calculate the net income
net_sales = (gross_sales)/(1 + STATE_TAX_RATE + COUNTY_TAX_RATE);
// Calculate total taxes paid.
total_tax_payment = (gross_sales - net_sales);
// cout << total_tax_payment; // output test
// Calculate total state taxes paid.
state_tax_payment = (total_tax_payment * (2.0/3.0));
// cout << state_tax_payment; //output test
// Calculate county taxes paid.
county_tax_payment = (total_tax_payment * (1.0/3.0));
//Display the information
cout << "Month: " << month << " " << year << endl;
cout << "--------------------" << endl;
cout << "Total collected:\t $" << fixed << setw(9) << setprecision(2) << right << gross_sales << endl;
cout << "Sales: \t\t\t\t $" << fixed << setw(9) << setprecision(2) << right << net_sales << endl;
cout << "County Sales Tax:\t $" << fixed << setw(9) << setprecision(2) << right << county_tax_payment << endl;
cout << "State Sales Tax:\t $" << fixed << setw(9) << setprecision(2) << right << state_tax_payment << endl;
cout << "Total Sales Tax:\t $" << fixed << setw(9) << setprecision(2) << right << total_tax_payment << endl;
return 0;
}
The output looks like this:
For what month is this? (Please type the name of the month.)
Answer: March
For what year?
Answer: 2008
How much was total sales at the register?
Answer: 26572.89
(lldb)
At "(lldb)" The program just stops... and Xcode indicates something I don't understand on "cout << "Month: " << month << " " << year << end;", telling where an issue is, then a lot of complex debugging info. The indicator is green colored.
Thanks again for any help!!!
Because state_tax_payment and total_tax_payment are not initialize state_tax_payment = net_sales / state_tax_payment; and county_tax_payment = net_sales / county_tax_payment; lines can be result in undefined behavior
Initialize the all float variables
Assign some value to state_tax_payment and total_tax_payment
Correct the type mention by ' Thomas Matthews'.
Then your program works fine . May be it exit after execution finish. so you can add something like 'getchar()' , std::cin.get() to pause the console.
The actual problem was identified by Tony D.
The debugger in Xcode had a breakpoint set to the particular line of code. I simply had to drag it out of the gutter. For those who don't know, that the green arrow on the left in of the lines of code is a breakpoint. Drag it to the bottom, out of the code, to remove it.
I'm sure I made a total newbie mistake, since I am one, but lesson learned.
I am having trouble getting my while loop to run. I am a very beginner coder and I have made many attempts with no success to make this work. I need help PLEASE!! Please be very specific and with laymen terms with your help since I am new to this.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string mystr1;
string mystr2;
cout << "Please provide your first and last name" << endl;
getline (cin, mystr1);
cout << endl;
cout << "Please provide your shipping address" << endl;
getline (cin, mystr2);
cout << endl;
cout << "Hello " << mystr1 << " and welcome to Faulk Couture
Handbags Boutique" << endl; // prints Hello and welcome to Faulk
Couture Handbags Boutique
cout << endl;
cout << "We have a variety of specialty and fashionable handbags to
select from. Please see below for the available products and their
descriptions." << endl;
cout << endl;
cout << "Product 1: Crosby Carryall in black priced at $395. This
sophisticated and spacious Crosby Carryall is a work-to-weekend favorite
and is finished with " << endl;
cout << "bound leather edges, a detachable leather strap and petite
brass turnlocks securing its two zippered compartments."<< endl;
cout << endl;
cout << "Product 2: Prairie satchel with chain nude priced at $450.
Crafted in lightweight pebble leather with a bit of sheen, this
gracefully curved shape distills" <<endl;
cout << "the satchel to its purest form. The simple design is finished
with a slender strap and an elegant chain detail that detaches for a
different look." << endl;
cout << endl;
cout << "Product 3: Faulk Swagger 20 brown priced at $325. This
Statement belting with double-turnlock hardware is one of our most
popular designs with a little bit of “swagger.” "<< endl;
cout << "Named for a bold, brass-trimmed Bonnie Cashin design from 1967,
this very modern carryall in refined pebble leather comes finished with
a detachable strap for crossbody wear." << endl;
cout << endl;
cout << "Product 4: Zip top tote in brown priced at $285. This
sophisticated and light weight in signature canvas with hand-finished
leather trim, this aptly named tote is made for one-the-go ease." <<
endl;
cout << "A modern, flared shape and oversized strap anchors add playful
proportions to its spacious, brightly lined design." << endl;
cout << endl;
cout << "Product 5: Wristlet 24 priced at $175. This striking, feminine
design in polished pebble leather has space enough for a tablet and an
elegant chain that converts it from wristlet to top handle." << endl;
cout << "A dog-leash clip on the strap and an embossed hangtag charm
finish it with signature Faulk Couture Style." << endl;
cout << endl;
double cost, total, amount;
int product;
cout << "Please enter the product number for your bag choice" << endl;
cin >> product;
cout <<"The respective price for this bag is: " << endl;
cin>>cost;
cout<<"Please enter the quantity you would like to purchase for this
bag choice" << endl;
cin>>amount;
total = cost*amount;
cout <<"Your total purchase price for " <<amount<< " qty of product
number " <<product<< " is " <<total<<"."<< endl;
int choice=1;
while (choice==1);
{
cout << "To purchase another bag, please enter 1 (anything else to
quit)" << endl;
cin >> choice;
cout << "Please enter the product number for your next bag choice" <<
endl;
cin >> product;
cout << "The respective price for this bag is: " << endl;
cin >> cost;
cout << "Please enter the quantity you would like to purchase for this
bag choice" << endl;
cin >> amount;
total = cost*amount;
cout <<"Your total purchase price for " <<amount<< " qty of product
number " <<product<< " is " <<total<<"."<< endl;
}
cout << endl;
return 0;
}
You're ending your while loop with a semicolon that's why it isn't entering the while loop
Here is the while loop without the semicolon
while (choice==1) {
cout << "To purchase another bag, please enter 1 (anything else to
quit)" << endl;
cin >> choice;
cout << "Please enter the product number for your next bag choice" <<
endl;
cin >> product;
cout << "The respective price for this bag is: " << endl;
cin >> cost;
cout << "Please enter the quantity you would like to purchase for this
bag choice" << endl;
cin >> amount;
total = cost*amount;
cout <<"Your total purchase price for " <<amount<< " qty of product
number " <<product<< " is " <<total<<"."<< endl;
}
I'm not sure how to loop or repeat a cin >> cashTendered if the amount tendered is less than the required amount.
So far, this is what I have.
if (cashTendered > || == total)
{
cout << "Your change is: $" << fixed << setprecision(2) << change << ".\n\n"
<< "Have a great day!\n\n\n\n\n";
}
else
{
cout << "You did not tender enough money to cover the total cost.\n"
<< "Please enter amount of cash tendered: $";
}
So now I want the if statement to repeat until true.
any suggestions?
Have a look at loops in c++. Also if condition can be shortened to >= instead of > || ==. Moreover, since you want to repeat until the cashTendered is >= total, you need a loop that checks the condition if cashTendered is < total.
while (cashTendered < total)
{
cout << "You did not tender enough money to cover the total cost.\n"
<< "Please enter amount of cash tendered: $";
cin >> cashTendered;
}
cout << "Your change is: $" << fixed << setprecision(2) << change << ".\n\n"
<< "Have a great day!\n\n\n\n\n";
while(true)
{
cin >> cashTendered
if (cashTendered >= total)
{
cout << "Your change is: $" << fixed << setprecision(2) << change << ".\n\n"
<< "Have a great day!\n\n\n\n\n";
break;
}
else
{
cout << "You did not tender enough money to cover the total cost.\n"
<< "Please enter amount of cash tendered: $";
}
}