Lec6 - Lecture 6 While loops counting sentinel input...

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

View Full Document Right Arrow Icon
Lecture 6 While loops 1 Lecture 6 While loops counting sentinel input failure
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture 6 While loops 2 While loop for Counting An example Read sales data from file Calculate total sales 6 10095 15 85 1275 10099 12 125 1500 10152 18 16 288 10158 10 78 780 10160 6 90 540 10166 8 101 808 number of lines of sales data number of parts sold part number Price of part price*numbe r
Background image of page 2
Lecture 6 While loops 3 #include<iostream.h> #include<math.h> #include<fstream.h> #include<iomanip.h> void main() { Header functions iomanip is for format int counter, count, item_number; double amount, unit_price, total_cost, total_sales; ifstream datain ( “salesdata1.txt", ios::in); datain >> count; cout << "count = " << count << endl; total_sales = 0; counter = 0; cout << " item amount price cost " << endl; Counting example code define variables open sales data file read count (6) echo print count initialize variables print table headings
Background image of page 3

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

View Full DocumentRight Arrow Icon
Lecture 6 While loops 4 cout << endl << "total sales = " << total_sales << endl << endl;
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/26/2008 for the course ENGR 1 taught by Professor X during the Spring '07 term at Lehigh University .

Page1 / 13

Lec6 - Lecture 6 While loops counting sentinel input...

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

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