Why is my output wrong? - c++

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double COUNTY_TAX = 0.02;
const double STATE_TAX = 0.04;
double totalSales;
void countyTax(double newCountyTax);
void stateTax(double newStateTax);
void total(double newTotal);
int main ()
{
cout << "Please enter the total dollar amount of sales: $";
cin >> totalSales;
countyTax(1);
stateTax(1);
total(1);
return 0;
}
void countyTax(double newCountyTax)
{
double newCountyTaxA;
newCountyTaxA = totalSales * COUNTY_TAX;
cout << "The county tax is: $" << newCountyTaxA << endl;
}
void stateTax(double newStateTax)
{
double newStateTaxA;
newStateTaxA = totalSales * STATE_TAX;
cout << "The State tax is: $" << newStateTaxA << endl;
}
void total(double newTotal)
{
double newTotalA, newStateTaxA, newCountyTaxA;
newTotalA = newStateTaxA + newCountyTaxA;
cout << "The total is: $" << newTotalA << endl;
}
hello guys! I am getting into modules in C++ and the above code compiles correctly but I can't seem to figure out why my output is wonky. I get the county tax and state tax to show properly but when the total shows I get "$nan" i was wondering if i could get some feedback on this? does it possibly have to do with the fact that within the module i am not using any global variables like i do with the totalSales and COUNTY_TAX and SALES_TAX and that when i declare newTotalA newStateTaxA newCountyTaxA they are declared but not assigned? just a tad confused here..THANKS!!!

the variables newStateTaxA and newCountyTaxA that are created and computed in countyTax and stateTax are local to those functions. Once the functions complete, those variables, and the values they contain, go away. In total you create new local variables with the same names. These have no relationship with the previously defined variables, apart from sharing names, and will not store the values previously computed in the other two functions.
The easiest solution, although not considered the most robust, is to create the two variables at the global scope, along with totalSales so that the values that they are assigned to in the two functions persist.
If you do not wish to use global variables (which I also don't care to use), you can declare them in your main function, and modify your other functions to return the calculated values:
double countyTax(double newCountyTax)
{
double newCountyTaxA;
newCountyTaxA = totalSales * COUNTY_TAX;
cout << "The county tax is: $" << newCountyTaxA << endl;
return newCountytaxA;
}
The calls in main() would then read:
newCountyTaxA = countyTax(1);

Your are doing a fundamental mistake here in the following code :
void total(double newTotal)
{
double newTotalA, newStateTaxA, newCountyTaxA;
newTotalA = newStateTaxA + newCountyTaxA;
cout << "The total is: $" << newTotalA << endl;
}
The Variables that you have created here "newStateTaxA", and "newCountyTaxA" does not have any relation to the other variables that you have created and assigned in the other methods, they are local for each method. You need to either make them global or return valued from those functions.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double COUNTY_TAX = 0.02;
const double STATE_TAX = 0.04;
double totalSales;
void Taxes();
int main ()
{
cout << "Please enter the total dollar amount of sales: $";
cin >> totalSales;
Taxes();
return 0;
}
void Taxes()
{
double countyTax, stateTax, total;
countyTax = totalSales * COUNTY_TAX;
stateTax = totalSales * STATE_TAX;
total = countyTax + stateTax;
cout << "The County Tax is: $" << fixed << setprecision(2) << countyTax << endl;
cout << "The State Tax is: $" << fixed << setprecision(2) << stateTax << endl;
cout << "The total is: $" << fixed << setprecision(2) << total << endl;
}
here is what I came up with. Everything works and outputs as desired. I guess now I am wondering if this type of setup with one module and multiple calculations inside it considered good programming?

Related

Calculations wont display in output

I'm a student in a basic programming class and I'm trying to complete this program for a class assignment. It's a simple program that calculates compounded interest by the inputs of the user. However, when writing the code, I noticed that the the result is 0 even though based on the input I would expect otherwise. Could anyone tell me why the program isn't showing results?
#include <iostream>
#include <cmath>
using namespace std;
// Declarations of Prototype
void futureValue(double* presentValue, float* interestRate, int* months, double* value);
// List of variables
double presentValue = 0;
float interestRate = 0;
double value = 0;
int months = 0;
// Start of Main function
int main(void)
{
cout << "What is the current value of the account?";
cin >> presentValue;
cout << "How many months will Interest be added to the account?";
cin >> months;
cout << "And what will be the Interest Rate of the account?";
cin >> interestRate;
cout << "After " << months << " months, your account balence will be $" << value << ".";
return 0;
}
void futureValue()
{
if (presentValue <= 0)
{
cout << "I'm sorry, you must have a current balence of more than 0.00 dollars to calculate.";
return;
}
else
{
value = presentValue * pow(interestRate + 1, months);
return;
}
}
Yes. You are not calling the futureValue function which would compute the value for you. Due to the value not being computed, it remains 0. Fix:
#include <iostream>
#include <cmath>
using namespace std;
// Declarations of Prototype
void futureValue(double* presentValue, float* interestRate, int* months, double* value);
// List of variables
double presentValue = 0;
float interestRate = 0;
double value = 0;
int months = 0;
// Start of Main function
int main(void)
{
cout << "What is the current value of the account?";
cin >> presentValue;
cout << "How many months will Interest be added to the account?";
cin >> months;
cout << "And what will be the Interest Rate of the account?";
cin >> interestRate;
futureValue(); //Here we compute the value
cout << "After " << months << " months, your account balence will be $" << value << ".";
return 0;
}
void futureValue()
{
if (presentValue <= 0)
{
cout << "I'm sorry, you must have a current balence of more than 0.00 dollars to calculate.";
return;
}
else
{
value = presentValue * pow(interestRate + 1, months);
return;
}
}

Uninitialized local variable that is actually initialized? [duplicate]

This question already has answers here:
How can I declare and define multiple variables in one line using C++?
(10 answers)
Comma as separator in variable initialization (not as operator)
(2 answers)
How does the Comma Operator work
(9 answers)
Closed 1 year ago.
I am writing a program that deals with values in an input file. My variables include total, taxtotal, subtotal, etc. & they have already been declared and initialized, yet I am getting two error messages: "uninitialized local variable 'subtotal' used" and the same for the variable "taxtotal".
Here is my source code:
#include "stdafx.h"
#include<stdio.h>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
ifstream shoppingBasketFile;
shoppingBasketFile.open("HW3_Data.txt");
bool isTaxed = false;
char taxValue = 0;
char inPrice[64];
char name[128];
double price, taxtotal, subtotal, total = 0;
if (shoppingBasketFile.is_open())
{
// display the header info:
cout << "o Thank you for shopping at StuffMart" << endl;
cout << setw(3) << left << "o "
<< setw(20) << left << "Item"
<< setw(12) << "Unit Price"
<< setw(4) << "Tax"
<< endl
<< "o -------------------------------------" << endl;
// parse the input file until end of file;
while (!shoppingBasketFile.eof())
{
// parse the item name:
shoppingBasketFile >> name;
cout << "Name = " << name << endl;
if (name == NULL)
{
// what should we really do here?
continue;
}
// parse the price:
shoppingBasketFile >> price;
if (price < 0 || price > 100000000000) {
continue;
}
cout << "Price = " << price << endl;
// parse the isTax flag:
shoppingBasketFile >> isTaxed;
shoppingBasketFile >> taxValue;
cout << "Is taxed? = " << taxValue << endl;
// if end of file break out of this loop:
if (!shoppingBasketFile.good()) break;
if (isTaxed == true) {
taxtotal = taxtotal + (.085 * price);
taxValue = 'Y';
}
else {
taxValue = 'N';
}
//display tax as Y instead of T/1
if (isTaxed == true) {
cout << "Tax: Y" << endl;
}
else {
cout << "Tax: N" << endl;
}
//compute the subtotals
subtotal = subtotal + price;
// display the item info:
cout << "name" << name << ", price: $" << price << ", is taxed: " << taxValue << endl;
// reset input values:
name, price, isTaxed = 0;
// end of while loop
}
//compute the final total:
total = subtotal + taxtotal;
//output the totals
cout << "o" << setw(37) << "---------------" << endl
<< "o " << setw(26) << "Subtotal $" << fixed << setprecision(2) << right << subtotal << endl
<< "o " << setw(26) << "Tax (8.5%) $" << fixed << setprecision(2) << right << taxtotal << endl
<< "o " << setw(26) << "Total $" << fixed << setprecision(2) << right << total << endl;
}
shoppingBasketFile.close();
return 0;
}
How can I eliminate these error messages? I am using Microsoft's Visual C++ compiler, if that matters.
In this declaration:
double price, taxtotal, subtotal, total = 0;
the type name double applies to all 4 variables, but the = 0 initialization applies only to total.
As others have said, the most direct fix is:
double price = 0, taxtotal= 0, subtotal = 0, total = 0;
but it's better style to declare each variable on its own line:
double price = 0.0;
double taxtotal = 0.0;
double subtotal = 0.0;
double total = 0.0;
Note that using 0 is perfectly valid (the int value will be implicitly converted to the double value 0.0), but using a floating-point constant is more explicit.
(I've chosen to align the initializers vertically. Some might prefer not to do that.)
I'm guessing you haven't gotten to pointers yet. When you do, you'll encounter another reason to declare each variable on its own line. This:
int* x, y, z;
defines x as an int*, but y and z as int. Using one declaration per line, as for the initializers above, avoids this opportunity for error and confusion:
int* x;
int* y;
int* z;
Once you get your code to compile, you'll have a problem with this line:
name, price, isTaxed = 0;
That's a valid statement, but it doesn't do what you think it does.
, is the comma operator. It evaluates its left and right operands in order, and yields the value of the right operand, discarding the value of the left operand. The statement evaluates and discards the current value of name, then evaluates and discards the current value of price, then assigns the value 0 to isTaxed. (Thanks to user4581301 for pointing this out.)
You could write this as:
name = price = isTaxed = 0;
(since an assignment yields the value that was assigned) or, more simply, as:
// name = 0;
price = 0.0
isTaxed = false;
I've commented out the assignment to name, since it's an array and you cannot assign a value to an array object. I won't show a corrected version because I don't know what you're trying to do here.
Suggestion: Start small, keep it simple, and confirm at each step that your code works before adding new code. I think you've tried to write too much code at once. You have nearly 100 lines of code that won't even compile. I've been programming for a long time and I wouldn't write that much code without making sure it compiles and runs.
It looks like you declared subtotal in your statement here:
double price, taxtotal, subtotal, total = 0;
but only initialized total with value 0, causing its use on the right side of the assignment to trigger the error:
subtotal = subtotal + price;
To initialize multiple items simply add the "=" explicitly.
Example:
double price = 0, taxtotal = 0, subtotal = 0, total = 0;

[C++} Not sure if this is even possible

I'm trying to find the average net pay for a payroll program. What I'm wondering is it possible to create an array from the outputted tabular data and use the array to calculate the average? Or do I have to do this a different way? My code thus far:
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
class employee {
ifstream fin;
char employeeid[12];
char employeename[20];
char martialstatus;
int hoursworked, overtime;
double hourlyrate, overtimepay, regularpay, grosspay, taxrate, taxamount, netpay, average;
void calculateGrosspay();
void calculateTax();
void calculateNetpay();
void printHeadings();
void printData();
double findAverage();
void printAverage();
public: employee();
~employee();
void printReport(); };
employee::employee(){
fin.open(payrollData.txt);
}; //Constructor
employee::~employee() {
fin.close(); } //Destructor
void employee::calculateGrosspay() {
if (hoursworked > 40) {
overtime = hoursworked - 40;
regularpay = hoursworked * hourlyrate;
overtimepay = overtime * (hourlyrate * 1.5);
grosspay = regularpay + overtimepay;
}
else grosspay = hoursworked * hourlyrate;
} //Calculate gross pay function
void employee::calculateTax() {
taxrate = .30;
taxamount = grosspay*taxrate;
} // calculate tax function
void employee::calculateNetpay() {
netpay = grosspay - taxamount;
} //Calculate net pay
void employee::printHeadings() {
cout << setw(45) << "-Employee Payroll Report-" << endl;
cout << "____________________________________________________________" << endl;
cout << "NAME ID HW OT RT-PAY OT-PAY Gross Tax NetPay" << endl;
cout << "____________________________________________________________" << endl;
} // print table headings
void employee::printData() {
cout << setprecision(2) << setiosflags(ios::fixed | ios::showpoint);
cout << setw(6) << employeename << setw(12) << employeeid << setw(4) << hoursworked << setw(3) << overtime << setw(8) << regularpay << setw(8)
<< overtimepay << setw(8) << grosspay << setw(8) << taxamount << setw(8) << netpay << endl;
} // print data
void employee::printReport() {
int i = 0;
printHeadings();
while (fin >> employeename >> employeeid >> hoursworked >> hourlyrate) {
calculateGrosspay();
calculateTax();
calculateNetpay();
printData();
i++;
}
}
double employee::findAverage() {
return average;
}
void printAverage() {
cout << endl;
cout << "The average netpay is" << average << endl;
}
void main() {
employee.printReport();
employee.findAverage();
employee.printAverage();
}
So after the program has printed the data to the console I want to find the average of the net pays and print it to the console. Best way to do this?
You'll probably need a vector like Soren mentioned. If you're trying to get some averages for all employees (which that's what I assume you're trying to do), then let's say we're going to try and get an average for gross pay.
You'll need a vector global, like such:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
using namespace std;
vector<double> netPayList;
double globalAverage;
You'll then need to add information to the vector when GrossPay is calculated as such:
void employee::calculateNetpay()
{
netpay = grosspay - taxamount;
netPayList.push_back(netpay);
}
Finally, we can calculate the average in employee::findAverage(), we should also probably use a for loop for this as well, and in my opinion we should ditch the public function of "employee" and switch that over to a traditional function, since we are trying to get the average for many "employee" instances. The average calculation will now look like this:
double findAverage()
{
for (int iterator = 0; iterator < netPayList.size(); iterator++)
{
average += netPayList[iterator];
}
globalAverage /= netPayList.size();
return globalAverage;
}
Anyway, that's basically the gist of it. Keep working on your stuff, but also I would suggest that you title your questions better. Someone with more gumption and SO privileges than I will most likely edit your OP.

Can't get rid of Error lnk2001 [duplicate]

This question already has answers here:
Can't set value of static object field (error LNK2001: unresolved external symbol)
(2 answers)
Closed 7 years ago.
Hey guys and gals I need some serious assistance. I have this final and its due in 2 days and some hours. However I am unable to resolve this lnk2001 error at the end of my program. Please help me I have no clue how to resolve. I left the instructors desires in the coding as comments.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
//
//CLASS DECLARATION SECTION
//
class EmployeeClass {
public:
void ImplementCalculations(string EmployeeName, double hours, double wage);
void DisplayEmployInformation(void);
static double Addsomethingup(EmployeeClass, EmployeeClass, EmployeeClass);
string EmployeeName;
double hours;
double wage;
double basepay;
double overtime_hours;
double overtime_pay;
double overtime_extra;
static double iTotal_salaries;
static double iIndividualSalary;
static double iTotal_hours;
static double iTotal_OvertimeHours;
};
int main()
{
system("cls");
cout << "Welcome to the Employee Pay Center" << endl;
/*
These are my three employees
*/
EmployeeClass Employ1;
EmployeeClass Employ2;
EmployeeClass Employ3;
/*
Here you will prompt for the first employee’s information.
Prompt the employee name, hours worked, and the hourly wage. For each piece
of information, you will update the appropriate class member defined above.
Example of Prompts
Enter the employee name =
Enter the hours worked =
Enter his or her hourly wage =
*/
cout << "Enter the employee name." << endl;
cin >> Employ1.EmployeeName;
cout << "Enter the hours worked." << endl;
cin >> Employ1.hours;
cout << "Enter his or her hourly wage." << endl;
cin >> Employ1.wage;
/*
Here you will prompt for the second employee’s information.
Prompt the employee name, hours worked, and the hourly wage. For each piece
of information, you will update the appropriate class member defined above.
Enter the employee name =
Enter the hours worked =
Enter his or her hourly wage =
*/
cout << "Enter the employee name." << endl;
cin >> Employ2.EmployeeName;
cout << "Enter the hours worked." << endl;
cin >> Employ2.hours;
cout << "Enter his or her hourly wage." << endl;
cin >> Employ2.wage;
/*
Here you will prompt for the third employee’s information.
Prompt the employee name, hours worked, and the hourly wage. For each piece
of information, you will update the appropriate class member defined above.
Enter the employee name =
Enter the hours worked =
Enter his or her hourly wage =
*/
cout << "Enter the employee name." << endl;
cin >> Employ3.EmployeeName;
cout << "Enter the hours worked." << endl;
cin >> Employ3.hours;
cout << "Enter his or her hourly wage." << endl;
cin >> Employ3.wage;
/*
Here you will implement a function call to implement the employ calcuations
for each object defined above. You will do this for each of the three
employees or objects.
The format for this step is the following:
[(object name.function name(objectname.name, objectname.hours,
objectname.wage)] ;
*/
Employ1.ImplementCalculations(Employ1.EmployeeName, Employ1.hours,
Employ1.wage);
Employ2.ImplementCalculations(Employ2.EmployeeName, Employ2.hours,
Employ2.wage);
Employ3.ImplementCalculations(Employ3.EmployeeName, Employ3.hours,
Employ3.wage);
EmployeeClass::Addsomethingup(Employ1, Employ2, Employ3);
}
/*
This section you will send all three objects to a function that will add up
the the following information:
- Total Employee Salaries
- Total Employee Hours
- Total Overtime Hours
The format for this function is the following:
- Define a new object.
- Implement function call [objectname.functionname(object name 1, object
name 2, object name 3)]
/*
} //End of Main Function*/
void EmployeeClass::ImplementCalculations (string EmployeeName, double
hours, double wage){
//Initialize overtime variables
basepay = wage;
overtime_hours=0.0;
overtime_pay=0.0;
overtime_extra=0.0;
if (hours > 40)
{
EmployeeClass::hours = 40.0;
EmployeeClass::overtime_hours = hours - 40;
EmployeeClass::overtime_pay = wage * 1.5;
EmployeeClass::overtime_extra = overtime_hours * overtime_pay;
EmployeeClass::iIndividualSalary = overtime_extra + (wage *
EmployeeClass::hours);
/*
This section is for the basic calculations for calculating overtime pay.
- base pay = 40 hours times the hourly wage
- overtime hours = hours worked – 40
- overtime pay = hourly wage * 1.5
- overtime extra pay over 40 = overtime hours * overtime pay
- salary = overtime money over 40 hours + your base pay
*/
/*
Implement function call to output the employee information. Function is
defined below.
*/
}
else
{
EmployeeClass::hours = hours;
EmployeeClass::overtime_hours = 0.0;
EmployeeClass::overtime_pay = 0.0;
EmployeeClass::overtime_extra = 0.0;
EmployeeClass::iIndividualSalary = wage * EmployeeClass::hours;
/* Here you are going to calculate the hours less than 40 hours.
- Your base pay is = your hours worked times your wage
- Salary = your base pay
*/
/*
Implement function call to output the employee information. Function is
defined below.
*/
} // End of the else
DisplayEmployInformation();
} //End of Primary Function
void EmployeeClass::DisplayEmployInformation(void)
{
// This function displays all the employee output information.
//This is your cout statements to display the employee information:
cout << "Employee Name ............. =" << EmployeeName << endl;
cout << "Base Pay .................. =" << basepay << endl;
cout << "Hours in Overtime ......... =" << overtime_hours << endl;
cout << "Overtime Pay Amount........ =" << overtime_pay << endl;
cout << "Total Pay ................. =" << iIndividualSalary << endl;
} // END OF Display Employee Information
double EmployeeClass::Addsomethingup(EmployeeClass Employ1, EmployeeClass
Employ2, EmployeeClass Employ3)
{
Employ1.DisplayEmployInformation();
// Adds two objects of class Employee passed as
// function arguments and saves them as the calling object's data member
values.
EmployeeClass::iTotal_hours = Employ1.hours + Employ2.hours + Employ3.hours;
double myhours;
EmployeeClass::iTotal_hours = Employ1.hours + Employ2.hours + Employ3.hours;
myhours = Employ1.hours + Employ2.hours + Employ3.hours;
EmployeeClass::iTotal_OvertimeHours = Employ1.overtime_hours +
Employ2.overtime_hours + Employ3.overtime_hours;
EmployeeClass::iTotal_salaries = Employ1.iIndividualSalary +
Employ2.iIndividualSalary + Employ3.iIndividualSalary;
/*
Add the total hours for objects 1, 2, and 3.
Add the salaries for each object.
Add the total overtime hours.
*/
// Then display the information below.
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " << endl;
cout << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%% " << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " << endl;
cout << "%%%% Total Employee Salaries ..... = " << iTotal_salaries << endl;
cout << "%%%% Total Employee Hours ........ = " << iTotal_hours << endl;
cout << "%%%% Total Overtime Hours......... = " << iTotal_OvertimeHours <<
endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " << endl;
return 0;
} // End of function
Non-integral static member variables must be defined outside the class definition.
class EmployeeClass
{
// ...
static double iTotal_salaries;
static double iIndividualSalary;
static double iTotal_hours;
static double iTotal_OvertimeHours;
};
double EmployeeClass::iTotal_salaries = 0.0;
double EmployeeClass::iIndividualSalary = 0.0;
double EmployeeClass::iTotal_hours = 0.0;
double EmployeeClass::iTotal_OvertimeHours = 0.0;

Basic problems with writing functions. Program randomly skips to the end

I'm very new to writing functions. This is my first attempt at using call by reference parameters specifically for a homework assignment. This program should calculate how long it takes to pay off a loan based on the users input of the amount they borrow, their monthly payment and the interest rate. The program should make sure the user doesnt input a payment number less than monthly interest amount and check for negative integers etc.
The area I commented out was my first go before i attempted to turn all of that into a function that uses call by reference parameters. At that point the program ran fine and i got output within a dollar of what I was looking for. After i rewrote the program like this and tried to make it a function, the program compiles but break to the bottom cout statements after asking for the interest rate. I assume my problem is somewhere within the interest1 function where i convert the percent to a decimal but i cant figure out why it would skip the rest of the functions afterwards.
Thanks for any advice you might have on this issue or anything else that looks wrong with the program itself.
#include <iostream>
#include <fstream>
using namespace std;
double amount();
double interest1();
double pay(double amt, double interest);
void payoff(double monthly, double Minpayment,double borrow,double interest, double&
totalinterest,int& month);
int main()
{
double monthly,month,totalinterest;
cout << fixed;
cout <<showpoint;
cout <<setprecision(2);
double borrow=amount();
double interest=interest1();
double Minpayment=pay(borrow, interest);
void payoff(double monthly,double Minpayment,double borrow,double interest,double&
totalinterest,int& month);
/*
// cout << "What is the monthly payment amount? \n";
// cin >> monthly;
// if(monthly<Minpayment)
// {
// cout << "You must make payments of at least: " << Minpayment++ << endl;
// cout << "Because your monthly payment is " << Minpayment << endl;
// cout << "Dont get overwhelmed with debt!!!!!! \n";
// }
// else
//
// {
// int month = 1;
// double totalinterest=0;
// do
// {
// double Minpayment=pay(borrow, interest);
// borrow=(borrow+Minpayment)-monthly;
// totalinterest=totalinterest+Minpayment;
// month++;
// }while(borrow>monthly);
*/
cout << "Your debt will be paid off in " << month << " months \n";
cout <<" with a final payment of " << borrow << endl;
cout << "You paid " << totalinterest << " in interest. \n";
return 0;
}
double amount()
{
double borrow,amt;
do
{
cout << "How much money do you want to borrow? \n";
cin >> amt;
if(amt<1)
cout << "You must enter a positive number!";
}while(amt<1);
borrow = amt;
return borrow;
}
double interest1()
{
double rate;
do
{
cout << "What is the annual interest rate expressed as a percent? \n";
cin >> rate;
if(rate<1)
cout << "You must enter a positive number!";
}while(rate<1);
double interest = (rate/12)*.01;
return interest;
}
double pay(double borrow,double interest)
{
double Minpayment=borrow*interest;
return Minpayment;
}
void payoff(double monthly,double Minpayment,double borrow,double interest, double&
totalinterest,int& month)
{
cout << "What is the monthly payment amount? \n";
cin >> monthly;
if(monthly<Minpayment)
{
cout << "You must make payments of at least: " << Minpayment++ << endl;
cout << "Because your monthly payment is " << Minpayment << endl;
cout << "Dont get overwhelmed with debt!!!!!! \n";
}
else
{
int month = 1;
do
{
double Minpayment=pay(borrow, interest);
borrow=(borrow+Minpayment)-monthly;
double totalinterest=totalinterest+Minpayment;
month++;
}while(borrow>monthly);
}
}
When you call a function inside main, you don't need to specify parameter types anymore:
void payoff(double monthly,double Minpayment,double borrow,double interest,double&
totalinterest,int& month); //wrong
should be
payoff(monthly, Minpayment,borrow, interest, totalinterest, month);
You should put double& andint& to the function's parameter list when define the function like you did.