From 7bd89b947967f56ffdcc8cbc7d1fd0ddfa8c3c6a Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Thu, 28 Feb 2019 11:18:46 -0500 Subject: [PATCH] Fixed bug for empty array in get product --- Algorithms.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Algorithms.hpp b/Algorithms.hpp index d6c2656..6c1aa78 100644 --- a/Algorithms.hpp +++ b/Algorithms.hpp @@ -1,10 +1,10 @@ //myClasses/Algorithms.hpp //Matthew Ellison -// Created: 11-8-18 -//Modified: 1-30-19 +// Created: 11-08-18 +//Modified: 02-28-19 //This file contains the declarations and implementations to several algoritms that I have found useful /* - Copyright (C) 2018 Matthew Ellison + Copyright (C) 2019 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -244,6 +244,12 @@ T getSum(const std::vector& ary){ //This is a function that returns the product of all elmements in a vector template T getProduct(const std::vector& ary){ + //Make sure there is something in the array + if(ary.size() == 0){ + return 0; + } + + //Multiply all elements in the array together T prod = 1; for(T cnt = 0;cnt < ary.size();++cnt){ prod *= ary.at(cnt);