I need some help. I need to write a program that will take a file that has a list of numbers and will find the largest number, the smallest number, the average, the sum, and the number of values on the list. It also needs a menu. This is what I have so far:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inputFile; //file stream object
int choice; // menu choice
int number; // to hold a value from file
int total; //to hold a value from file
int large; // to hold largest value from file
int small; // to hold smallest value from file
int sum; // to hold sum of the values from file
int average; // to hold the average values from file
int quantity; // to hold the number of values entered
inputFile.open("TopicDin.txt"); // Open the file
do
{
//display the menu and get a choice
cout << "Make a selection from the list:";
cout << "1. Get the largest value";
cout << "2. Get the smallest value";
cout << "3. Get the sum of the values";
cout << "4. Get the average";
cout << "5. Get the number of values entered";
cout << "6. End this program";
cout << "Enter your choice: ";
cin >> choice;
//Validate the menu selection
while (choice < 1 || choice > 6)
{
cout << "Please enter 1, 2, 3, 4, 5, or 6: ";
cin >> choice
}
// Respond to the user's menu selection
switch (choice)
{
case 1:
inFile << number
cout << large;
break;
case 2;
cout << small;
break;
case 3;
inFile << number
do
number += number
while(number != " ");
cout << number;
break;
case 4;
cout << average;
break;
case 5;
cout << quantity;
break;
case 6;
cout << "Program ending. \n";
break;
}
} while (choice != 6)
return 0;
}
I'm just stuck on how to evaluate the list to find these numbers.
Mod edit - Fixed code tags
~BetaWar

New Topic/Question
Reply




MultiQuote





|