Simple C++ program, not compiling, I’m having trouble?


4 Responses to “Simple C++ program, not compiling, I’m having trouble?”

  1. Murali says:

    your are declaring “cost”, “dp -downpayment”, “inetrest” and “yrs” as string. which is wrong.

    Declare them as float or double.

  2. Noir says:

    This is why you should declare all the variables first (like in C ) and then ask for input to avoid confusion. You’re also missing the closing ‘}’ at the end I’m guessing that’s a typo.

  3. sspade30 says:

    What is this?
    cout << showpoint << fixed << setprecision(2);

    Delete that line, it is nonsense.

    You didn’t declare “dp”

    den and den2? Those aren’t declared. Yes, if you make some of those floats it will help. You’ll want to getline for the address, otherwise you’ll just get up to the first space.

  4. Chris C says:

    You should avoid mixing getline() calls with simple cin>> calls.
    Variables should be defined at the beginning of the function, unless they’re really brief (such as a simple for loop).
    Define variables of the type that you need, and use a simple buffer to hold temporary strings.
    Here’s the repaired code.

    // Mortgage Calculator

    #include
    #include
    #include
    #include
    using namespace std;

    int main()
    {
    string name;
    string address;
    string city;
    string state;
    string zip;
    string buffer;
    double cost, dp, ir, yrs;

    // User input
    cout << “Welcome to Eric’s Mortgage Calculator!”<< endl;
    cout << “First,what is your name?” << endl;
    getline(cin,name);

    cout << “Your address?” << endl;
    getline(cin,address);

    cout << “Your city?” << endl;
    getline(cin,city);

    cout << “Also, your state?” << endl;
    getline(cin,state);

    cout << “And your zip code?” << endl;
    getline(cin,zip);

    cout << “Okay, now you’re house…” << endl;
    cout << “What is the cost of your home?” << endl;
    getline(cin,buffer);
    cost = atof(buffer.c_str());

    cout << “And how much is the downpayment?” << endl;
    getline(cin,buffer);
    dp = atof(buffer.c_str());

    cout << “What is the interest rate of your loan? (Please enter with decimal =))” << endl;
    getline(cin,buffer);
    ir = atof(buffer.c_str());

    cout << “How many years is the loan for?” << endl;
    getline(cin,buffer);
    yrs = atoi(buffer.c_str());

    //Calculations and assignments
    //float monthlyPayment = cost * (ir * (1 + ir));
    //float num2 = pow(num, 12);
    //float den = (1 + ir);
    //float den2 = pow(den, 12);
    //float den3 = (den2 – 1);
    //float monthlyPayment = (num2 / den3);
    float monthlyPayment = cost * (1 – pow((1 + (ir / 1200)), (yrs * 12) * -1));

    //Output
    //Their info
    cout << endl;
    cout << endl;
    cout << “Your information:” << endl;
    cout << left ;
    cout << “Name:” << name << endl;
    cout << “Address:” << address << endl;
    cout << “City:” << city << endl;
    cout << “State and Zip:” << state << “,” << zip << endl;

    // Their calculations
    cout << endl;
    cout << endl;
    cout << “And here are your calculations,” << name << endl;
    cout << “Cost:” << cost << endl;
    cout << “Down Payment:” << dp << endl;
    cout << “Interest rate:” << ir << endl;
    cout << “Life of loan:” << yrs << endl;
    cout << “Approximate Mortgage Payment:” << fixed << setprecision(2) << monthlyPayment << endl;

    system( “pause” );
    }

Leave a Reply

*


Celebrity Sex Tapes | Kim Kardashian Sex Tape