| | |
c++ homework
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2005
Posts: 13
Reputation:
Solved Threads: 0
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 ')'
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 ')'
C++ Syntax (Toggle Plain Text)
#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; } }
Last edited by alc6379; Feb 23rd, 2005 at 6:17 pm. Reason: added [code] tags
Don't use void main; it's always int
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 !=
C++ Syntax (Toggle Plain Text)
while(name != "end"); { ..........
You are comparing in fact 2 strings (or char arrays); for this, you should use strcmp, not !=
![]() |
Similar Threads
- We only give homework help to those who show effort (Computer Science)
- Need help with Computer Science homework (Computer Science)
- Dynamic memory allocation homework (C++)
- Homework Help!! Priority Queue ?? (Computer Science)
Other Threads in the C++ Forum
- Previous Thread: Chargen -- A character Generator
- Next Thread: Reading Binary files via stdin
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





