I am getting a little frustrated with this program. Im a beginner with a little c++ bg. The user has to make a choice to either find the max, min, or avg of a set of numbers the user enters. My problem is the min function does not work. It prompts me to enter numbers but they do not save at all. I have to use ctrl-x to exit the program. My other problem is that when a choice > 3 is entered, it says invalid choice but continues to the avg function
#include <iostream>
#include <limits> // for INT_MIN AND INT_MAX
using namespace std;
// Function prototypes
int max(int n); // find maximum number among n numbers
int min(int n); // find minimum number among n numbers
int avg(int n); // find average number for n numbers
int main()
{
// Declare variables
int choice, count, num;
count = 0;
// Prompt user for choice and read choice
cout << "Enter a choice (0 = Max, 1 = Min, 2 = Avg, and 3 = Exit): ";
cin >> choice;
// While loop continues until invalid choice is entered
while (choice != 3)
{
if (choice < 0 || choice > 3)
{
cout << "Invalid choice. Try again." << endl;
}
cout << "How many numbers of input? ";
cin >> num;
// Function descriptions
// Function int max calculates the maximum number of
// n numbers entered by the user. It returns maxNum
// as the maximum number
int max(int n)
{
int count = 0, num, maxNum = 0;
// Function int min
// int min calculates the minimum number of a set of
// numbers entered by the user. It returns minNum as
// the minimum number. Parameter int n is the
// number of numbers that the user must enter
int min(int n)
{
int count = 0, num, minNum = 1000;
cout << "Enter " << n << " numbers" << endl;
Thank you for fixing my min function. I can't believe it was that simple. However, the return 0; makes my program break but I have to continue looping the choice until they enter a valid one