This program is supposed to give me the average, largest, smallest, sum, and number of entries from a group of integers.
The results I'm getting are impossibly wrong. I suspect that the "while (cin >> x) " has something to do with it, but I may be wrong. What I'm trying to do there is say "if you're still getting input, keep at it".
The other thought I had is that it is taking end of file (ctrl+Z) as a value. Anyway, this is the code (I know it's not pretty, I'm new at this!):
And this is what I get for results, irregardless of the entries:
// entering a list of integers and finding the number of entries, the smallest/largest entry,
// the average of the entries, and their sum. (that's the theory, anyway : ) )
using namespace std;
int get_data (int);
int count_integers (int,int);
int sum_int (int , int);
int large_num (int, int);
int small_num (int, int);
int avg_total (int ,int , int, int);
int results (int ,int, int, int, int);
int main ()
sum_int (sum, x);
large_num (x, largest);
small_num (x, smallest);
avg_total (x, count, sum, avg);
results (count, sum, avg, largest, smallest);
int get_data (int x) //getting input from keyboard
cout<<"Please enter a list of integers,([Ctrl]+Z to end):"<<endl;
int count_integers (int x, int count) // counting the # of entries
int sum_int (int sum, int x) // getting the sum of the entries
sum = sum + x;
int large_num (int x, int largest) //finding the largest entry
if (x >= largest)
largest = x;
int small_num (int x, int smallest) //finding the smallest entry
smallest = x;
int avg_total (int x,int count, int sum,int avg) // finding the average of the ehtries
avg = count/sum;
int results (int count, int sum, int avg,int smallest, int largest) //print results
cout<<"You entered "<<count<<" integers."<<endl;
cout<<"the sum of the integers is "<<sum<<"."<<endl;
cout<<"The average of the integers is "<<avg<<"."<<endl;
cout<<"The largest integer entered was "<<largest<<"."<<endl;
cout<<"The smallest integer entered was "<<smallest<<"."<<endl;
Any ideas? I know, it's something glaringly obvious. I think I just need that one hint that'll make me say "Oooohh, ok.."
Please enter a list of integers,([Ctrl]+Z to end):
You entered 4370432 integers.
the sum of the integers is 4198592.
The average of the integers is 2293600.
The largest integer entered was 2009196833.
The smallest integer entered was 2293664.
Press any key to continue . . .
If there is a good tutorial or page that might help to clarify things, please clue me in. I am still woefully lacking in decent reference texts, so for now I'm using the web.