lecture21-march11

lecture21-march11 - Announcements Lecture 21 Read Chapter...

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

1 Announcements Lecture 21 Read Chapter 14 for after the break Assignment 4 – Due Friday – Write down your stats (SLOC,hrs, logic errors) Friday lecture and recitations called off Topics for today – enumerations – Random numbers (pg 570-571) – Performance evaluation enum Type An enumeration type stands for a set of named integer constants that specify all the legal values that a variable of that type can hold The advantage (over #define) is they follow the scope rules E.g. enum weekday { SUN, MON, TUE, WED, THURS, FRI, SAT }; /* C gives these the values of 0,1,2,. . . 6 by default */ weekday today; /* declare a variable of that enum type */ scanf (“%d”, &today); if ( today == MON | | today == WED || today == FRI ) { printf ( "Today is a ee312 lecture day;go to class \n"); } Enumerations (2) /* you can give the identifiers specific int values instead */ enum coin_value { PENNY=1, NICKEL=5, DIME=10, QUARTER=25, HALF_DOLLAR=50, DOLLAR=100}; coin_value money; /* declare a variable of that type*/ scanf (“%d”, &money); printf ( ”the value of money input is a ”); switch(money) { case PENNY: printf ( "penny”); break; case NICKEL: printf ( "nickel”); break; case DIME: printf ( "dime”); break; case QUARTER: printf ( "quarter”); break; case HALF_DOLLAR: printf ( "half_dollar”); break; case DOLLAR: printf ( "dollar”); break; default: printf ( ” non-legitimate coin value”); } Simulating Randomness in C What is a random number?

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.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern