Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Finally!! This code works perfectly!!!! What do you think?? I'm going to bed now, 4 a.m. again as usual!! Thanks everybody for the help! Can anyone tell me why some of you put "void" after the main ()?????


Code:
#include <stdio.h>

main ()

{

	int a, b, tens;
	
	
	printf ("Enter Numerical Grade:") ;
	scanf ("%d", &a) ;
	
	
	
	
	if (a > 100 || a < 0) {
		printf ("error, error, Danger Will Robinson! Danger!!\n") ;
		return 0 ;
		}
		
		
	printf ("Letter Grade: " ) ;
		tens = a / 10 ;
	
	switch (tens) {
		case 10: printf ("A\n") ;
			break;
		case 9: printf ("A\n") ;
			break;
		case 8: printf ("B\n") ;
			break;
		case 7: printf ("C\n") ;
			break;
		case 6: printf ("D\n") ;
			break;
		case 5: printf ("F\n") ;
			break;
		case 4: printf ("F\n") ;
			break;
		case 3: printf ("F\n") ;
			break;
		case 2: printf ("F\n") ;
			break;
		case 1: printf ("F\n") ;
			break;
		case 0: printf ("F\n") ;
			break;
		}	
			
	return 0 ;
	
}

pull out the print and break after cases: 10,5,4,3,2,1
You can just use the fall-through to get the same affect with sorter code.

-Lee
 
Scott, in "int main(void)", "void" tells the computer that your program shouldn't take any command-line arguments. If it took them, main's first line would say something like this, "main(char *argv[], int argc). " The argv array would hold the command-line arguments, and argc would stand for how many arguments that array held.
 
Scott, in "int main(void)", "void" tells the computer that your program shouldn't take any command-line arguments. If it took them, main's first line would say something like this, "main(char *argv[], int argc). " The argv array would hold the command-line arguments, and argc would stand for how many arguments that array held.

Not trying to be a jerk, but just wanted to point out that the count is first and the array of arguments is second;
Code:
int main(int argc, char *argv[]) {
...
}

-Lee
 
Not trying to be a jerk, but just wanted to point out that the count is first and the array of arguments is second;
Code:
int main(int argc, char *argv[]) {
...
}

-Lee
Thanks, Lee. I should have refreshed my memory before I answered Scott's question. In our detail-oriented profession, we need to remind one another of details. I usually don't program in C-like languages.

I know you're not trying to be a jerk. Even if you were trying to be one, you'd fail at being one. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.