Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering 101 Engineering 101 Lecture 13 10/18/07 Data Types Quote of the Day Quote of the Day Judge people by their questions rather than by their answers. ­ Voltaire Some Notes on Project 4 Some Notes on Project 4 Due tomorrow, 10/19 @ 9pm If you use ‘rand() % 4’ to get your random number, your path should be the same as the sample program provided you assign 0=N, 1=S, 2=E, and 3=W This occurs since the random number stream will always be the same each time you run the program If we actually set a different value for the random number seed each time, this would not occur Either way, your output will be correct as long as you only move one direction on each step and log the closest/farthest positions properly Using Selection To Check Using Selection To Check Program Status One of the most important uses of selection is to check the status of a command or action cout << “Enter a positive number” << endl; cin >> n; exit() is if (n <= 0){ defined in the cout << n << “ is not positive” << endl; cstdlib library. exit(EXIT_FAILURE); It terminates } the program. cout << “The inverse square root is “ << 1.0/sqrt(static_cast<double>(n))<<endl; Streams are a particular case in point since whenever you try to open or read from a file you don’t know if the file might not exist or be finished. ifstream infile(“myfile.data”); if( infile.fail() )...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online