Can someone help me out a little and point out my error here....
I got the program to run, but it should end after five runs. Instead it goes on and on and on..... Thanks.
Thanks.Code:#include <iostream> #include <cmath> using namespace std; //Functions used ... void instructions (); int calculations (); //----------------------------------------------------- int main () { instructions (); for(int x=0; x<=5; ++x) calculations (); return 0; } //------------------------------------------------ int calculations () { int numNumbers = 0; do { cout << "Enter the number of numbers in your group " << "and then press the <Enter> key. "; cin >> numNumbers; cout << endl; if(numNumbers <= 0) cout << "Error! You must enter a number greater than 0." << endl << endl; } while(numNumbers <= 0); int largest = 0; int smallest = 0; float total = 0.0; for (int counter = 0; counter < numNumbers; ++counter) { int num; cout << "Enter a number "; cin >> num; total += num; if(counter == 0) { largest = num; smallest = num; } else if (num > largest) { largest = num; } else if (num < smallest) { smallest = num; } } float avg = total / numNumbers; cout << "The largest number in the group is " << largest << endl; cout << "The smallest number in the group is " << smallest << endl; cout << "The average of the numbers are " << avg << endl; cout << endl; return 0; }



LinkBack URL
About LinkBacks


