// John Doe // reading and writing files demo #1 // day of week?? #include #include using namespace std; void displayMenu(); // displays menu // ******************* constant declaration statements ******* const double BOOK_PRICE = 9.00; // price per book const double MOVIE_PRICE = 13.97; // price per movie int main() { // *************** variable declaration statements ******* int numBooks = 0; // # of books for this order int totalNumBooks = 0; // total # of books ordered by customer int numMovies = 0; // # of movies for this order int totalNumMovies = 0; // total # of movies ordered by customer double bookSubtotal = 0.0; // subtotal cost of books double movieSubtotal = 0.0; // subtotal cost of books double grandTotal = 0.0; // grandtotal of all purchases bool userWantsToExit = false; // flag variable to exit while loop int menuChoice = 0; // customer's menu choice ifstream infile("V:/Desktop/data.txt"); // file with input data (use forward slashes) ofstream outfile("V:/Desktop/output.txt"); // file for output while (!userWantsToExit) { //displayMenu(); infile >> menuChoice; if (menuChoice == 1) { //cout << "Enter number of books: "; infile >> numBooks; if (numBooks >= 0 && numBooks <= 10) { totalNumBooks += numBooks; } else { //cout << "Invalid input." << endl; } } else if (menuChoice == 2) { //cout << "Enter number of movies: "; infile >> numMovies; if (numMovies >= 0 && numMovies <= 10) { totalNumMovies += numMovies; } else { //cout << "Invalid input." << endl; } } else if (menuChoice == 3) { userWantsToExit = true; } else { //cout << "Invalid input." << endl; } } // *************** output display ************************ bookSubtotal = totalNumBooks * BOOK_PRICE; movieSubtotal = totalNumMovies * MOVIE_PRICE; grandTotal = bookSubtotal + movieSubtotal; outfile << "\nYou owe $" << grandTotal << endl << endl; infile.close(); outfile.close(); system("pause"); return 0; }// end of main // displays menu void displayMenu() { cout << "\n1 books" << endl; cout << "2 movies" << endl; cout << "3 checkout" << endl; cout << "Enter your choice: "; }// end of displayMenu