samedi 6 février 2021

Calculating Cash On Cash Returning 0 for the result

I am creating a class function where it returns Cash on Cash return which gives you a percentage and is a key indicator to see if you are getting a good ROI. I created the function, but for some reason its not giving me the answer I want which is "3%" or "50%. Cash On Cash return is usually (yearly cash flow / total cash invested ). It is just returning 0.

double cashOnCashReturn(int cashFlowMonthly, int buyingPrice, double downPaymentP, double closingCost, int repairs) {

    int fullMonth = 12;

    int yearlyCashFlow = cashFlowMonthly * fullMonth;

    double downPaymentPercentage = downPaymentP/100;

    int downPaymentCashInvested = downPaymentPercentage * buyingPrice;

    long closingCostTotal = closingCost * buyingPrice;

    int cashInvestment = downPaymentCashInvested + repairs + closingCostTotal;

    double cashOnCash = (yearlyCashFlow / cashInvestment) * 100;

    cout << fixed << setprecision(0);

    return cashOnCash;
}

My main function is below

int main()
{   
    string address;
    int buyingPrice;
    int rent;
    int cashFlowMonthly;
    int downPayment;
    double closingCostPercent = 0.05;
    int repairCost;

    // Mortgage Calculator Variables
    // double annualInterestRate;
    // double loanAmount;
    // double monthlyInterestRate;
    // double numberOfPayments;
    // double totalPayBack;
    // double monthlyPayment;

    cout << "Address: ";
    getline(cin,address);
    cout << "Buying Price: ";
    cin >> buyingPrice;
    cout << "Down Payment Percentage: ";
    cin >> downPayment;
    std::cout << "Repair Cost: ";
    std::cin >> repairCost;
    cout << "Rent Monthly: ";
    cin >> rent;
    std::cout << "Cashflow Monthly: ";
    std::cin >> cashFlowMonthly;

    realEstate firstHome;
    firstHome.setAddress(address);
    firstHome.setBuyingPrice(buyingPrice);
    firstHome.setRent(rent);
    
    std::cout <<"\n";
    std::cout << "================================================" << std::endl;
    std::cout << "Real Estate Calculator Created By Austin Nguyen" << std::endl;
    std::cout << "================================================" << std::endl;
    std::cout << "Address: " << firstHome.getAddress() << std::endl;
    std::cout << "\n";
    std::cout << "Buying Price: " << firstHome.getBuyingPrice() << std::endl;
    std::cout << "\n";
    std::cout << "Rent: " << firstHome.getRent() << std::endl;
    std::cout << "\n";
    std::cout << "Does It Pass One Percent Rule? " << firstHome.onePercentRule(buyingPrice,rent) << std::endl;
    std::cout << "\n";
    std::cout << "Cash On Cash Return: " << firstHome.cashOnCashReturn(cashFlowMonthly,buyingPrice,downPayment,closingCostPercent,repairCost);
    std::cout << "\n";
    std::cout << "================================================" << std::endl;
    std::cin.clear();

Aucun commentaire:

Enregistrer un commentaire