Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <stdio.h>
#include <stdlib.h> // remember if you plan to use exit(), you need
					// this header file
 


main() 
{
	// Despite being a long program, you only need two variables:
	// one for the first menu and one for the second menu
	
	int choice1;
	int choice2;
	
	// The potential decade choices
	
	printf("What do you want to see?\n");
	printf("1. The 1980's\n");
	printf("2. the 1990's\n");
	printf("3. The 2000's\n");
	printf("4. Quit\n");
	
	//The top menu choice and the switch statement that makes the
	// resulting
	//information appear are encased in a do-while loop that
	//ensures one
	// of the four menu choices are made
	do
	{
		
		printf("Enter your choice: ");
		scanf(" %d", &choice1);
		switch (choice1)
		{
			//In the first case, the user picked the 1980's. Now it
			//time to see what specific info they need.
			
			case (1) : 
			{
				printf("\nWhat would you like to see?\n");
				printf("1. Baseball\n");
				printf("2. The movies\n");
				printf("3. US Presidents\n");
				printf("4. Quit\n");
				
				
				printf("Enter your choice: ");
				scanf(" %d", &choice2);
				
				if (choice2 ==1)
				{
					printf("\n\nWorld Series Chapions ");
					printf(" of the 1980's:\n");
					printf("1980: Philadelphia Phillies\n");
					printf("1981: Los Angeles Dodgers\n");
					printf("1982: St. Louis Cardinals\n");
					printf("1983: Baltimore Orioels\n");
					printf("1984: Detroit Tigers\n");
					printf("1985: Kansas City Royals\n");
					printf("1986: New York Mets\n");
					printf("1987: Minnesota Twins\n");
					printf("1988: Los Angeles Dodgers\n");
					printf(" 1989 Oakland A's\n");
					printf("\n\n\n");
					break;
					
				} else if (choice2 == 2)
				{
					printf("\n\nOscar winning movies in the 1980's:\n");
					printf("1980: Ordinary People\n");
					printf("1981: Chariots of Fire\n");
					printf("1982: Ghandi\n");
					printf("1983: Terms of Endearment\n");
					printf("1984: Amadeus\n");
					printf("1985: Out of Africa\n");
					printf("1986: Platoon\n");
					printf("1987: The Last Emperor\n");
					printf("1988: Rain man\n");
					printf("1989: Driving Miss Daisy");
					printf("\n\n\n");
					break;
				} else if (choice2 == 3)
				{
					printf("\n\n US Presidents in the 1980's:\n");
					printf("1980: Jimmy Carter\n");
					printf(" 1981-1988: Ronald Reagen\n");
					printf("1989: George Bush\n");
					printf("\n\n\n");
					break;
					
				} else if (choice2 == 4)
				{
					exit(1);
				} else
				{
					printf("Sorry, that is not a valid choice!\n");
					break;
				}
			}
			
			//This is the case for the 1990's.
			// Unlike the top menu, there isn't a data validation
			//do-while loop
			
			case (2) :
				{
					printf("\n\n What would you like to see?\n");
					printf("1. Baseball\n");
					printf("2. The movies\n");
					printf("3. US Presidients\n");
					printf("4. Quit\n");
					
					printf(" Enter you choice:");
					scanf(" %d", &choice2);
					
					if (choice2 ==1)
					{
						printf("\n\n World Series Champions of");
						printf("the 1990's:\n");
						printf("1990: Cincinatti reds\n");
						printf("1991: Minnesota Twins\n");
						printf("1992: Toronto Blue jays\n");
						Printf("1993: Toronto Blue Jays\n");
						printf("1994: No World Series\n");
						printf("1995: Atlanta Braves\n");
						printf("1996: New York Yankees\n");
						printf("1997: Florida Marlins\n");
						printf("1998: New York Yankees\n");
						printf("1999 New York Yankess\n");
						printf("\n\n\n");
						break;
						
					} else if (choice2 == 2)
					{
						printf("\n\n Oscar winning Movies in ");
						printf(" the 1990's:\n");
						printf("1990: Dances with Wolves\n");
						printf("1991: The Silence of the Lambs\n");
						printf("1992: Unforgiven\n");
						printf("1993: Schindlers List\n");
						printf("1994: ?\n");
						printf("1995: ??\n");
						printf("1996: The English Patient\n");
						printf("1997: Titanic\n");
						printf("1998: Shakespere in Love\n");
						printf("1999: American Beauty\n");
						printf("\n\n\n");
						break;
					} else if (choice2 == 3)
					{
						printf("\n\nUS Presidents in the 1990's:\n");
						printf("1990-1992: George Bush\n");
						printf("1993-1999: Bill Clinton\n");
						printf("\n\n\n");
						break;
					} else if (choice2 == 4)
					{
						exit (1);
					} else
					{
						printf("Sorry, that is not a valid choice!\n");
						break;
					}
				}
				
				// The section for when the user selects the 2000's
				case (3) :
					{
						printf("\n\nWhat would you like to see?\n");
						printf("1. Baseball\n");
						printf("2. The Movies\n");
						printf("3. US Presidents\n");
						printf("4. Quit\n");
					
						printf("Enter your choice:");
						scanf(" %d", &choice2);
						
						if (choice2 == 1)
						{
							printf("\n\nWorld series Champions of ");
							printf("The 2000's:\n");
							printf("2000: New York Yankees\n");
							printf("2001: Arizona Diamondbacks\n");
							printf("2002: Anaheim Angels\n");
							printf("2003: Florida Marlins\n");
							printf("2004: Boston Red Sox\n");
							printf("2005: Chicago White Sox");
							printf("2006: St. Louis Cardinals\n");
							printf("2007: Boston Red Sox\n");
							printf("2008: Philadelphia Phillies\n");
							printf("2009: New York Yankees\n");
							printf("\n\n\n");
							break;
						} else if (choice2 == 2)
						{
							printf("\n\nOscar winning movies in ");
							printf("the 2000's: \n");
							printf("2000: Gladiator\n");
							printf("2001: A Beautiful Mind\n");
							printf("2002: Chicago\n");
							printf("2003: The Lord of the Rings\n");
							printf("2004: Million Dollar Baby\n");
							printf("2005: Crash\n");
							printf("2006: The Departed\n");
							printf("2007: No Country for Old Men\n");
							printf("2008: Slumdog Millionaire\n");
							printf("2009: The Hurt Locker\n");
							printf("\n\n\n");
							break;
						} else if (choice2 == 3)
						{   
							printf("\n\nUS Presidents in the 2000's\n");
							printf("2000: Bill Clinton\n");
							printf("2001-2008: George W Bush\n");
							printf("2009: Barack Obama\n");
							printf("\n\n\n");
							break;
						} else if (choice2 == 4)
						{	
							exit(1);
							
						} else
						{
							printf("Sorry, that is not a valid choice!\n");
							break;
						}
		}
		case (4) :
			exit (1);
			default : printf("\n%d is not a valid choice.\n");
				printf("Try again.\n");
				break;
	}
} while ((choice1 < 1) || (choice1 > 4));

	return 0;
}


What I have tried:

I have tried looking over the program and nothing obvious his coming up.
Posted
Updated 5-Mar-17 6:40am
Comments
Graeme_Grant 5-Mar-17 12:32pm    
Great to see the formatting, named variables, and code comments...

However, that is a lot of repetitive code. Why not use arrays to hold the questions, then passed them off to a function. That way it simplifies the code and makes debugging a lot simpler...

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
Have you set breakpoints to catch the flow of your code? The debugger can help you greatly and save you heaps of time.

I can see an error that need fixing:
C++
default : printf("\n%d is not a valid choice.\n");
should be:
C++
default : printf("\n%d is not a valid choice.\n", choice1);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900