ok, help!!! I'm totally lost. I have to use a file stream program and add names to file, then keep count of file names, then display the count of names entered and the names entered. Use a loop to enter names until prompt to end.
these are just two of the errors I get when trying to use for loops. I had error with while loop also.
error C2143: syntax error : missing ';' before ')'
error C2143: syntax error : missing ';' before ')'
#include <iostream.h> // This is used for the cout's and cin's
#include <fstream.h> // This is used to read from and write to files
#include <stdlib.h> // This gives us the exit(1) command
void main()
{
char filename[12];
char name [20];
int count = 0;
int x = 0;
char end;
int y = 0;
// int ch;
cout << "Enter the filename: ";
cin >> filename;
cout << endl;
// Creating an instance of outbound data
ofstream outfile;
outfile.open(filename, ios::app);
if (outfile.fail())
{
cout <<"The file failed to open" <<endl;
exit(1);
}
cout << "Enter names to the file called: "<< filename <<endl;
cout << "Enter end to stop entering names." << endl;
cout << endl;
count = 1;
while(name != "end");
{
cout << "Enter names: " << endl;
cin >> name;
count++;
cout << endl;
}
//send data to outfile
outfile << name;
outfile << "\n";
// Closing the outfile to free up memory
outfile.close();
// Creating an instance of inbound data
ifstream infile;
// Opening the infile "filename" for reading
infile.open(filename);
// Reading the contents of "filename"
infile >> name;
infile.close();
for(y = 0; y <= count; y++)
{
cout << "You have entered " << count << "names"<< endl;
}
for( x = 0, x <= 20, x++)
{
cout <<"The name you have entered is: " << name << endl;
}
}