reading_from_file3 - infile >>...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 // reading from file #include <fstream> // to read from files or write to files #include <iostream> // cin, cout using namespace std int main() { double pricePerBook = 0.0 d double bookShipping = 0.0 int numBooks = 0 double totalPrice = 0.0 ifstream infile("C:/Temp/a3data.txt") // or // ifstream infile //"C:/Temp/a3data.txt") infile >> pricePerBook
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: infile &gt;&gt; bookShipping infile.close() cout &lt;&lt; &quot;How many books? &quot; cin &gt;&gt; numBooks double bookSubtotal = pricePerBook * numBooks + bookShipping * numBooks cout &lt;&lt; bookSubtotal &lt;&lt; endl ofstream outfile(&quot;C:/Temp/output.txt&quot;, ios::app) // append mode outfile &lt;&lt; bookSubtotal &lt;&lt; endl outfile.close() return 0 }...
View Full Document

Ask a homework question - tutors are online