/*  PA1 Spring 2023  CpSc 1010
    apples/oranges in mis-labeled jars
	we worked through the solution in class earlier in the semester
	now they can write a program to show the shortest way to solve this
	a.  start with jar labeled both
		1-b. if get apple, then you know the jar labeled both is apples
		1-c. and jar labeled oranges is really both
		1-d. and jar labeled apples is really oranges

		2-b. if get orange, then you know the jar labeled both is oranges
		2-c. and jar labeled apples is really both
		2-d. and jar labeled oranges is really apples

	program should allow user to try both sequences
    program should also enforce valid letters as input

	program requires if-statements and loops (no arrays are required)
*/


#include <stdio.h>

int main() {
	char choice;
	int goAgain = 1;

	printf("\nSolution to apples/oranges problem. \n\n");
	printf("\nThe first step is to choose from the jar that is labeled both.  ");
	do {
		printf("\n\nWhat did you get?  a (for apple) or o (for orange): ");
		scanf(" %c", &choice);
		if ( (choice != 'A') && (choice != 'a') && (choice != 'O') 
	         && (choice != 'o') )
			printf("\nInvalid input.  Make another choice.\n\n");
	} while( (choice != 'A') && (choice != 'a') && (choice != 'O') 
	         && (choice != 'o') );

	while (goAgain) {
		if (choice == 'a' || choice == 'A') {
			printf("\nYou chose an apple, which means that:  ");
			printf("\n\n1. The jar that is labeled as ""both"" is really apples."
					"\n2. The jar labeled as ""oranges"" is really both."
					"\n3. The jar labeled as ""apples"" is really oranges.\n\n");
		}
		else if (choice == 'o' || choice == 'O') {
			printf("\nYou chose an orange, which means that:  ");
			printf("\n\n1. The jar that is labeled as ""both"" is really oranges."
					"\n2. The jar labeled as ""apples"" is really both."
					"\n3. The jar labeled as ""oranges"" is really apples.\n\n");
		}

		printf("\n\nLet's try a different sequence\n");
		printf("Choose from the jar that is labeled both. \n");
		do {
			printf("\nWhat did you get?  a (for apple) or o (for orange)"
					" or q (for quit): ");
			scanf(" %c", &choice);
			if ( (choice != 'A') && (choice != 'a') && (choice != 'O') 
	         	&& (choice != 'o') && (choice != 'q') && (choice != 'Q') )
				printf("\nInvalid input.  Make another choice.\n\n");
			if (choice == 'q' || choice == 'Q')
				goAgain = 0;
		} while( (choice != 'a') && (choice != 'A') && (choice != 'o')
				&& (choice != 'O') && (choice != 'q') && (choice != 'Q') );
	}


	return 0;
}


