this C++ problem. It keeps coming up with errors

here the problem
Write a program named writeToFile.cpp which writes and formats the output. Ask the user for the filename and write to that file. Assume the user enters prices.txt as the file name. First do error checking to see if the file has opened successfully for writing. Then your program should write to the output file formatted as a table.

Books 39.95
CDs 3.22
Pens 1.08
Pencils .99

can you also let me know if I'm on the right track
here what I have so far:

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main () {
ofstream fout;
string filename;
cout<<"please give me the filename to write to: ";
cin>> filename;
fout.open (filename, c_str());
if(fout.fail())
{
cout<<"file open fail!";
}
fout<< "Books 39.95"<<endl;
fout<<"CDs 3.22"<<endl;
fout<<"Pens 1.08"<<endl;
fout<<"Pencils .99" <<endl;
const double;
Books=39.95;
CDs=3.22;
Pens=1.08;
Pencils=.99;
fout<< setprecision(2)<<Books<<endl;
fout<< setprecision(2)<<CDs <<endl;
fout<< setprecision(2)<<Pens<<endl;
fout<< setprecision(2)<<Pencils<<endl;
fout.close();
Last edited on
Answered in your other thread.
http://www.cplusplus.com/forum/beginner/212935/

Please do not double post.
Topic archived. No new replies allowed.