lecture3a

lecture3a - Wednesday,October8th ReviewChallenge...

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

View Full Document Right Arrow Icon
Wednesday, October 8th Review Challenge Variable Scoping Rules Control Structures The  while  loop The  do-while  loop
Background image of page 1

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

View Full DocumentRight Arrow Icon
One last time…. Programming Language Inventor  Or Serial Killer See if you can guess who uses a keyboard and who uses a  chainsaw!
Background image of page 2
Review Challenge What does the following program print out? #include <iostream> using namespace std; int main(void) { int eyeBalls, nostrils, total; eyeBalls = 2; nostrils = 2; total = --eyeBalls + nostrils++ * 3; cout << “total: “ << total; return(0); }
Background image of page 3

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

View Full DocumentRight Arrow Icon
int main(void) { int boogers; cout << "Enter number of boogers: "; cin >> boogers; if (boogers < 3) { int real_boogers = 10*boogers; cout << “I think you really have “ << real_boogers << “ boogers!\n”; } cout << “Go blow your nose!\n”; } Variable Scoping Rules Not only can you declare variables in your  main function, but you can also declare variables inside blocks  enclosed by  {  and  } . boogers 99 2 2 real_boogers 20 cout << real_boogers; // SYNTAX ERROR!
Background image of page 4
Control Structures We use control structures in our C++ programs to let us  make decisions  and  repeat operations multiple times.   IF  student is asleep  THEN      put shaving cream on                    __ their head ELSE        teach normally WHILE  carey has hairs left        complain about lecture       complain about homework
Background image of page 5

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

View Full DocumentRight Arrow Icon
The while Loop   The while loop allows us to repeat (iterate) many times through a set o logic.   Usage:while (  expression is true  )      do-this-statement; No semi! {     do-this;     and-this;     etc… } int count = 0;    count < 2       cout <<count<<“\n”; ++count; cout << “Done”;     count  0 0 < 2? 0 1 1 < 2? 1 2 2 < 2? Done
Background image of page 6
The while Loop {     do-this;     etc… }       Usage:while (  expression is true  ) int count = 0;    count < 2       cout <<count<<“\n”; ++count; cout << “Done”;     count  0 0 < 2? 0 < 2? 0 < 2? 0 0 0
Background image of page 7

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

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

Page1 / 22

lecture3a - Wednesday,October8th ReviewChallenge...

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