midterm cheat sheet 2

midterm cheat sheet 2 - SWITCH MULTIPLE CASE LABELS switch...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science cheat sheet FUNCTIONS /* a function header goes here */ int iDoThis (int iInput, float fInput) { int iOutput = 0; iOutput = (int) fInput * iInput / 42; return (iOutput); } /* end function iDoThis() */ CELSIUS TO FAHRENHEIT float fCelsToFahr (float fCelsius) { float fFahren = 0.0; fFahren = ((9.0 / 5.0) * fCelsius) + 32.0; return (fFahren); } /* end function fCelsToFahr() */ IF if (x <= 10) printf (“X is 10 or less.\n”); else printf (“X is greater than 10.\n”); /* end if */ COMPLEX IF if (fGrade >= 90.0) printf (“You get an A.\n”); else if (fGrade >= 80.0) printf (“You get a B.\n”); else if (fGrade >= 70.0) printf (“You get a C.\n”); else if (fGrade >= 60.0) printf (“You get a D.\n”); else printf (“You get an F.\n”); /* end if */ SWITCH switch (controlling expression) { case labels } /* end switch control variable */
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: SWITCH MULTIPLE CASE LABELS switch (iInput) { case 1: case 3: case 5: case 7: case 9: printf (“Input is odd.\n”); break; case 0: case 2: case 4: case 6: case 8: printf (“Input is even.\n”); break; default: printf (“Only one digit please.\n”); break; } /* end switch iInput */ ANOTHER EXAMPLE switch (cTrigOp) { case ‘c’: case ‘C’: dValue = cos (dAngle); break; ... default: printf (“Invalid input %c.”, cTrigOp); break; } /* end switch cTrigOp */ WHILE AND DO-WHILE syntax while (logical expression) { statements } do { statements } while (logical expression) ; FOR EXAMPLE for (fCels = fLowCels; fCels <= fUppCels; fCels+=fStep) { fFahr = fCelsToFahr (fCels); printf ("%7.2f\t\t%7.2f\n", fCels, fFahr); }...
View Full Document

This note was uploaded on 12/05/2011 for the course CSC 234 taught by Professor Hutch during the Spring '08 term at Cal Poly.

Ask a homework question - tutors are online