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

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 Document Right 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 Document Right 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 Document Right 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 Document Right 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 <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 Right Arrow Icon
Ask a homework question - tutors are online