Assignment 5

Due Thursday, 4/11 at the start of class.

You are to redo homework 4 with functions. Here is the main program that you must use. Here is a brief description of the functions.

intro( )
Displays a description of the program.
menu( )
Displays the choices for the user.
get_int_and_bad( )
Will read an integer from the user and keep track of how many bad choices were made. Validate that the number is between a given minimum and maximum. If it is not in this range, then tell the user the input was incorrect, and read a new value. Continue this process until a valid number is entered. You must also handle the case if a character is entered instead of a number.
get_int( )
Will read an integer from the user. Validate that the number is between a given minimum and maximum. If it is not in this range, then tell the user the input was incorrect, and read a new value. Continue this process until a valid number is entered. You must also handle the case if a character is entered instead of a number.
get_double( )
Will read a double from the user. Validate that the number is between a given minimum and maximum. If it is not in this range, then tell the user the input was incorrect, and read a new value. Continue this process until a valid number is entered. You must also handle the case if a character is entered instead of a number.
calc_by_count( )
Will calculate the value of pi using a count loop. The number of times to loop is one of the arguments.
calc_by_condition( )
Will calculate the value of pi using a conditional loop. The smallest term to use is one of the arguments.
output_from_count
Will display the results that were calculated in the calc_by_count function.
output_from_condition
Will display the results that were calculated in teh calc_by_condition function.
final_output
Will display the times that each menu option was chosen and the number of times that a bad menu choice was made.
int main() {
	int		choice, terms;
	double	pi, epsilon;
	int		total_1, total_2, total_bad;

	intro();

	total_1 = 0;
	total_2 = 0;
	total_bad = 0;
	do {
		menu();
		get_int_and_bad(&choice, &total_bad, MIN_MENU, MAX_MENU);
		if (choice == 1) {
			total_1++;
			printf ("\nHow many terms (maximum of %d)? ", MAX_TERM);
			terms = get_int (MIN_TERM, MAX_TERM);
			calc_pi_by_count (terms, &pi, &epsilon);
			output_from_count (pi, epsilon);
		} else if (choice == 2) {
			total_2++;
			printf ("\nAbsolute value of the smallest term (minimum of %.8f)? ", MIN_EPS);
			epsilon = get_double (MIN_EPS, MAX_EPS);
			calc_pi_by_condition (epsilon, &pi, &terms);
			output_from_condition (pi, terms);
		} else {
			final_output (total_1, total_2, total_bad);
		}
	} while (choice != 3);

	return 0;
}