I have an assignment where I have to create a menu and then depending on the menu choice the program has to call from a list of numbers from a file and find the highest and lowest value, sum, average and number of values in the list. I think I almost have it figured it but im having trouble with the equations to get the values.
#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{
char choice; // To hold a menu choice
// Constants for menu choices
constchar LARGE_CHOICE = 'A',
SMALL_CHOICE = 'B',
SUM_CHOICE = 'C',
AVERAGE_CHOICE = 'D',
TOTAL_CHOICE = 'E',
END_CHOICE = 'F';
// Display the menu and get a choice
cout << "Make a selection from the list\n"
<< "A. Get the largest value\n"
<< "B. Get the smallest value\n"
<< "C. Get the sum of the values\n"
<< "D. Get the average\n"
<< "E. Get the number of values entered\n"
<< "F. End this program\n\n"
<< "Enter your choice --> ";
cin >> choice;
ifstream inputFile;
double sum = 0;
double number;
inputFile.open("random.txt");
// Respond to the user's menu selection
if (choice == 'A' || choice == 'a')
{
for (int count = 0; inputFile >> number; count++)
{
}
cout << "The largest value is " << sum << ".\n";
}
elseif (choice == 'B' || choice == 'b')
{
for (int count = 0; inputFile >> number; count++)
{
}
cout << "The smallest value is " << << ".\n";
}
elseif (choice == 'C' || choice == 'c')
{
for (int count = 0; inputFile >> number; count++)
{
sum += number;
}
cout << "The sum of the values entered is " << sum << ".\n";
}
elseif (choice == 'D' || choice == 'd')
{
for (int count = 0; inputFile >> number; count++)
{
}
cout << "The average of the values entered is " << average << ".\n";
}
elseif (choice == 'E' || choice == 'e')
{
for (int count = 0; inputFile >> number; count++)
{
}
cout << "The number of values entered is " << << ".\n";
}
elseif (choice == 'F' || choice == 'f')
{
for (int count = 0; inputFile >> number; count++)
{
}
cout << "Program ending\n\n";
<< "Press Enter to end --> ";
}
else
cout << choice << " is an invalid value.";
inputFile.close();
return 0;
}