Month and Annual costs
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Month and Annual costs

  1. #1
    Join Date
    Oct 2012
    Posts
    1

    Month and Annual costs

    The point of this is to calculate the total of the monthly costs of these 6 expenses and then to show the annual cost. However, there's just a couple of things that's giving me problems and it's the calcMonCost in my code. The error says that it is more than one instance of overload function and also that an unresolved external symbol. Everything else is fine. What does this mean?

    code:

    #include <iostream>
    #include <iomanip>

    using namespace std;

    void calcMonCost (double, double, double, double, double, double &);
    void calcAnnCost (double, double, double, double, double, double &);
    void getData(double &lnPymnt, double &insure, double &gas, double &oil, double &tires, double &maint);

    int main ()
    {
    double lnPymnt;
    double insure;
    double gas;
    double oil;
    double tires;
    double maint;

    getData(lnPymnt, insure, gas, oil, tires, maint);

    problem area --->calcMonCost(lnPymnt, insure, gas, oil, tires, maint);

    system("pause");
    return 0;
    }

    void getData(double &lnPymnt, double &insure, double &gas, double &oil, double &tires, double &maint)
    {
    cout << "Enter monthly loan payments: ";
    cin >> lnPymnt;

    cout << "Enter monthly insurance: ";
    cin >> insure;

    cout << "Enter monthly gas expenses: ";
    cin >> gas;

    cout << "Enter monthly cost of oil: ";
    cin >> oil;

    cout << "Enter monthly cost of tires: ";
    cin >> tires;

    cout << "Enter monthly maintenance cost: ";
    cin >> maint;
    }

    void calcMonCost (double lnPymnt, double &insure, double &gas, double &oil, double &tires, double &maint)
    {
    double monTotal;
    monTotal= lnPymnt + insure + gas + oil + tires + maint;
    cout << "Total monthly expenses cost is " << monTotal <<"." << endl;
    }

    void calcAnnCost (double monTotal)
    {
    double annTotal;
    annTotal = monTotal * 12;
    cout << "The annual expenses cost is " << annTotal << "." << endl;
    }

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,062

    Re: Month and Annual costs

    The reason is that your calcMonCost signature is different on two places. First you define it as:
    Code:
    void calcMonCost (double, double, double, double, double, double &);
    And lower you define it as:
    Code:
    void calcMonCost (double lnPymnt, double &insure, double &gas, double &oil, double &tires, double &maint)
    Which is not the same, because the first version accepts 5 doubles and 1 reference to a double, while the second version accepts 1 double and 5 references to doubles.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center