cs16wk04c

cs16wk04c - seed value – Use srand( time(NULL) ) for...

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

View Full Document Right Arrow Icon
First Exam First Exam Wednesday, January 26 Wednesday, January 26 (Review: Monday, January 24) (Review: Monday, January 24) (Discuss results: much of Jan. 28) (Discuss results: much of Jan. 28)
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 switch switch ( controlling integral expression ) { case constant integral expression : statements ; break; // important case constant integral expression : statements ; break; ... default: statements to do if no case matches ; } – See ~mikec/cs16/demo04/gradepoints.c Continued from last week
Background image of page 2
Aside: random integers Aside: random integers z Quick look-ahead to chapter 4 topic – Just a follow-up to Lab03 z If not ch, include <stdlib.h> for rand , srand functions, and <time.h> for time function z Use rand() to get pseudorandom value from 0 to RAND_MAX (defined in <stdlib.h> too) – But always same sequence unless change
Background image of page 3

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

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

Unformatted text preview: seed value – Use srand( time(NULL) ) for surprise result z Use % operator to restrict range (e.g., see ~mikec/cs16/demo04/rolldice.c while while while ( boolean expression ) operation ; /* or a block, delimited by { } */ z E.g., do something 10 times: int counter = 0; while (counter < 10) { ... ++counter; } – e.g., Program chapter3_1 (p. 103) z Note: better structure type for “counter-controlled” loop soon z while is best type when termination is uncertain – e.g., processing the characters or “tokens” in a string – e.g., reading unlimited lines of data from a file // initialize // compare to limit // increment (or otherwise change)...
View Full Document

This note was uploaded on 03/01/2011 for the course CMPSC 16 taught by Professor Costanzo during the Spring '11 term at UCSB.

Page1 / 4

cs16wk04c - seed value – Use srand( time(NULL) ) for...

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

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