I am having problems returning the value that I want from my function getPrices(). This part of the program is supposed to prompt the user to take up to 25 prices or exit with a -1. Every time I display the count though, all I get is zero. Any help on this would be greatly appreciated.
#include <iostream>
usingnamespace std;
// Function Prototypes
int getPrices(double price[], int array_size);
void calcStats(double price[], int array_size);
int main()
{
constint array_size = 25;
double price[array_size] = {};
int count = 0;
int num;
// Prompt user to enter up to 25 prices or a -1 when done
cout << "Enter up to 25 prices or a -1 when done.\n";
// Call to function getPrices()
getPrices(price, array_size);
cout << endl;
cout << "The number of prices entered was: ";
cout << count << endl;
return 0;
}
//***********************************************************************
// Function getPrices() *
// Gets input (prices)from user *
//***********************************************************************
int getPrices(double price[], int array_size)
{
double input = 0.0;
int num = 0;
int count = 0;
while (input != -1 && count < array_size)
{
cout << "Enter price " << (count + 1) << " \n";
cin >> input;
price[count] = input;
count++;
if (input == -1)
{
price[count - 1] = NULL;
return count;
}
}
return count;
}