When I try to start my program without debugging, the command prompt screen flashes and disappears, and I was wondering whether there is any way to keep the screen without using cin.get(), and to get the "press any key to continue" to display. I want this to happen so I can select all and copy the output from the command prompt screen.
/*Arooj Mohammed C++Ch13Ex20
Average price: $28.07
*/
//Ch13Ex20.cpp- calculates and displays the average price of the company's inventory items.
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::ifstream;
using std::ios;
using std::setiosflags;
using std::setprecision;
int main()
{
//declare variables
double total = 0.0;
double average = 0.0;
double price = 0.0;
int x = 0;
//create file object and open the file
ifstream inFile;
inFile.open("prices.txt", ios::in);
//determine whether the file was opened
if (inFile.is_open())
{
inFile >> price;
inFile.ignore();
//read a line from the file
while (!inFile.eof())
{
total = total + price;
x = x + 1;
inFile >> price;
inFile.ignore();
} //end while
average = total / x;
cout << "Average price: $" << setprecision(4) << average << endl;
//close the file
inFile.close();
} //end if
else
cout << "File could not be opened." << endl;
//end if
return 0;
} //end of main function