View Single Post
  #7   Spotlight this post!  
Unread 09-06-2007, 18:22
Pat McCarthy Pat McCarthy is offline
FiM Volunteer
FRC #0067 (HOT Team)
Team Role: Alumni
 
Join Date: May 2003
Rookie Year: 2003
Location: Grand Rapids, MI
Posts: 593
Pat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond reputePat McCarthy has a reputation beyond repute
Send a message via AIM to Pat McCarthy
Re: C Programming Homework Help Needed

Back again...

I'm only concerned with a small portion of my program at the moment.
This part collects an integer value for use to set the color of an object later in the program, then checks to make sure it is within a certain range of numbers. If the number isn't within that set of numbers, it is supposed to ask the user to enter again, then collects a value again.

Currently, whether the value entered is within the parameters that I want, this chunk of program gets stuck in the error checking loop. Oddly, when you enter a two digit integer, it breaks the loop.

Code:
	/* Collects shape selection from user and checks for invalid inputs */
	do
	{
		color_error = 0;
		
		/* Collects desired color from user */
		printf("\nSelect color:\n");
		printf("BLACK (0), BLUE (1), GREEN (2)\n");
		printf("CYAN (3), RED (4), MAGENTA (5)\n=>");
		fflush(stdin);
		scanf("%d", &color);
		printf("Selected color: %d\n", color);
		fflush(stdin);

		/* Valitdate entry */
		switch (color)
		{
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
				break;
				
			default:
				color_error = 1;
				printf("Please select one of the available colors\n");
				break;
		}
	}
	while(color_error);
I've attached an image of what happens when the code is executed and the entire program's code. It needs to be compiled with a special .lib file that my prof wrote. (something in the forums is keeping me from attaching it)
Attached Thumbnails
Click image for larger version

Name:	Color_input.jpg
Views:	110
Size:	46.5 KB
ID:	5582  
Attached Files
File Type: c shape.c (2.1 KB, 88 views)
__________________
2003-2006: FRC Team 67 - Drafter, Driver, Student Leader
2006 Volunteering: Kettering Kickoff Ref, Team Ford FIRST Robotics Invitational Ref
2007 Volunteering: GLR Field Reset/Repair; WMR Robot Inspector and Scorekeeper; MARC Referee
2008 Volunteering: WMR Planning Committee, WMR Scorekeeper, MARC Ref, IRI Scorekeeping, WMRI Scorekeeping & DJ
2009 Volunteering: Kettering District, MARC, IRI, and WMRI Scorekeeper/Field Power Controller
2010 Volunteering: Kettering District, MARC, IRI, and WMRI Scorekeeper/Field Power Controller
2011 Volunteering: Waterford District, West Michigan District, MARC, & IRI DJ
2012 Volunteering: Waterford District, West Michigan District DJ

Last edited by Pat McCarthy : 09-06-2007 at 18:29.