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;
}
	
}

Recommended Answers

All 4 Replies

:lol: Single step the code with your debugger. That will reveal exaclty where it is choking and how. BTW, the while loop has a subtle defect.

thx I found the two errors for loop I had a comma instead of semi colon.

yes while loop is buggy and driving me nuts.
I have error warning C4101: 'end' : unreferenced local variable
been going through book and past programs I did and will keep trying to figure out what I am doing wrong.

Don't use void main; it's always int

while(name != "end");
{
..........

The while statements never ends with a semicolon.
You are comparing in fact 2 strings (or char arrays); for this, you should use strcmp, not !=

thx for the excellent help all!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.