Okay, so here's my set of problems: I need a simple error check, so that if the user enters the wrong type of character, he/she will be notified and allowed to re-enter a new value. Secondly, I need some sort of loop that allows the user, after having running the program at least once successfully, to choose whether or not to run it again. Finally, since this program is supposed to read in only odd integers, tally the number of odd integers, calculate the average, and give the lowest and highest odd integers entered, I need some help with that, as although I don't enter 0, the lowest odd integer is always printed as if it were 0. Here's my code, so far:
#include <iostream>
#include <iomanip>
#define Exit -1
using namespace std;
int main(int argc, char** argv)
{
int cur_num;
int min_num = 0;
int max_num = 0;
int odd_num_count = 0;
int sum_odd_num = 0;
double avg_num = 0;
while (true) {
cout << "Enter a Positive Integer or -1 to Exit: \n"; // display message
cin >> cur_num; //enter a positive integer value
if (cur_num == Exit) break; //exit statment to initiate calculation
if ((cur_num%2 != 0) && (cur_num > 0)) //varifies that value entered is odd
{
if ( cur_num <= min_num) min_num = cur_num; //varifies if value entered is smallest number
if (cur_num >= max_num) max_num = cur_num; //varifies if value entered is largest number
odd_num_count++; //increments the odd number counter
sum_odd_num = sum_odd_num + cur_num; //algorith for odd number counter
avg_num = sum_odd_num/odd_num_count; //algorith for average value calculation
cout << fixed << showpoint << setprecision (2);
}
}
cout << "Results:\n"; //display message
cout << "Number of Odd Integers Entered: " << odd_num_count << "\n"; //display message
cout << "Average Value: " << avg_num << "\n"; //display message
cout << "Largest Odd Integer Entered: " << max_num << "\n"; //display message
cout << "Smallest Odd Integer Entered: " << min_num << "\n"; //display message
fflush (stdin);
cin.get();
return 0;
}
Thanks for your time and assistance.
Desh2350