BIL104E_w3 - } } return 0;} Switch Case-Program II/II...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
BIL104E INTRODUCTION TO SCIENTIFIC AND ENGINEERING COMPUTING (C) WEEK - 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Switch Case switch ( constant ) { case Constant1 : Instraction [break] case Constant2 : Instraction [break] . . . case Constant N : Instraction [break] default: Instraction; }
Background image of page 2
Switch Case Write a program for grade scaling. Grades are asked, and the user gives the grades from keyboard. Then grades must be scaling with switch case. 90-100 Grade A 80-89 Grade B 70-79 Grade C 60-69 Grade D <59 Fail
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
#include<stdio.h> main(){ int mark; printf(" Enter your mark, please:"); scanf("%d",&mark); if (mark<0 || mark>100) printf("Mark is not valid\n"); else{ switch( mark / 10 ) { case 10: case 9: printf("Grade: A\n"); break; Switch Case-Program I/II
Background image of page 4
case 8: printf("Grade: B\n"); break; case 7: printf("Grade: C\n"); break; case 6: printf("Grade: D\n"); break; default: printf("Grade: Fail!\n"); break;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } } return 0;} Switch Case-Program II/II Functions Write a rolling dice program Choose number of dice face (standart 6) Create a function for rolling dice (random number generation) Roll twice and determine the result (win, lose, tie) #include &lt;stdio.h&gt; #include &lt;math.h&gt; int rolldice(); int main(){ int face; int yours; int comps; printf(&quot;Choose your dice:\n&quot;); scanf(&quot;%d&quot;,&amp;face); yours=rolldice(face); printf(&quot;Your dice is %d\n&quot;,yours); comps=rolldice(face); printf(&quot;Computers dice is %d\n&quot;,comps); Functions-Program I/II if(yours&gt;comps) printf(&quot;You won\n&quot;); else if (yours&lt;comps) printf(&quot;You lost\n&quot;); else printf(&quot;Tied\n&quot;); return 0; } int rolldice(int facenum){ int result=rand()%facenum+1; return result; } Functions-Program II/II...
View Full Document

Page1 / 8

BIL104E_w3 - } } return 0;} Switch Case-Program II/II...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online