final cheat sheet functions

final cheat sheet functions - break; } /* end switch iInput...

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

View Full Document Right Arrow Icon
Computer Science cheat sheet FUNCTIONS int iDoThis (int iInput, float fInput) { int iOutput = 0; iOutput = (int) fInput * iInput / 42; return (iOutput); } CELSIUS TO FAHRENHEIT float fCelsToFahr (float fCelsius) { float fFahren = 0.0; fFahren = ((9.0 / 5.0) * fCelsius) + 32.0; return (fFahren); } 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 (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”);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 { Prompt for input b/w iLow and iHigh Get input If (iInput &lt; iLow) Tell user; Else if (iInput &gt; iHigh) Tell user; } while ((iInput&lt;iLow) || (iInput&gt;iHigh)) ; FOR EXAMPLE for (fCels = fLowCels; fCels &lt;= fUppCels; fCels+=fStep) { fFahr = fCelsToFahr (fCels); printf (&quot;%7.2f\t\t%7.2f\n&quot;, fCels, fFahr); } READING ATM BALANCE FILE In main: { FILE *fpIn; fpIn = fopen (atmbal.dat, r); fscanf (fpIn, %lf, &amp;dChckBal); fscanf (fpIn, %lf, &amp;dSaveBal); fscanf (fpIn, %lf, &amp;dVisaBal); fclose (fpIn); }...
View Full Document

Ask a homework question - tutors are online