# BIL104E_w3 - return 0 Switch Case-Program II/II Functions...

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

BIL104E INTRODUCTION TO SCIENTIFIC AND ENGINEERING COMPUTING (C) WEEK - 3

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

View Full Document
Switch Case switch ( constant ) { case Constant1 : Instraction [break] case Constant2 : Instraction [break] . . . case Constant N : Instraction [break] default: Instraction; }

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

View Full Document
#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

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

View Full Document

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

View Full Document
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 <stdio.h> #include <math.h> int rolldice(); int main(){ int face; int yours; int comps; printf("Choose your dice:\n"); scanf("%d",&face); yours=rolldice(face); printf("Your dice is %d\n",yours); comps=rolldice(face); printf("Computers dice is %d\n",comps); Functions-Program I/II if(yours>comps) printf("You won\n"); else if (yours<comps) printf("You lost\n"); else printf("Tied\n"); return 0; } int rolldice(int facenum){ int result=rand()%facenum+1; return result; } Functions-Program II/II...
View Full Document

{[ snackBarMessage ]}

### Page1 / 8

BIL104E_w3 - return 0 Switch Case-Program II/II Functions...

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

View Full Document
Ask a homework question - tutors are online