| | |
Program with many errors
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2005
Posts: 24
Reputation:
Solved Threads: 0
This is my first attempt at creating a program and I am having great problems. The program is meant to scan a file and increment a counter if specific words are found. Can anyone let me know where I'm going wrong,Thanks
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <conio.h>
using namespace std;
int main (void)
{
string string1;
int location;
char userName; //The students log-in name
int markCounter //Counter for adding up students mark
system("cls"); // Clear the screen
cout << "Marking Program" << endl << endl;
ifstream infile("checkUserName.txt", ios::in);
//Get students username
cout << "Enter Students Username: ";
cin >>string1;// entered username
// Check students username validity
userName.find_first_of("checkUserName.txt");
if string1 /found then
cout << "Username not found"<<;
else
ifstream infile("string1.txt", ios::in); //open students file
ifstream infile("markScheme.txt", ios::in);
while (getline(markScheme, line1)) {
if (line1.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line2)) {
if (line2.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line3)) {
if (line3.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line4)) {
if (line4.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line5)) {
if (line5.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line6)) {
if (line6.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line7)) {
if (line7.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line8)) {
if (line8.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line9)) {
if (line9.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line10)) {
if (line10.find(search) != string::npos)
++1 counter;
//Display students mark
cout << "Students mark is (counter)";
}
}
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <conio.h>
using namespace std;
int main (void)
{
string string1;
int location;
char userName; //The students log-in name
int markCounter //Counter for adding up students mark
system("cls"); // Clear the screen
cout << "Marking Program" << endl << endl;
ifstream infile("checkUserName.txt", ios::in);
//Get students username
cout << "Enter Students Username: ";
cin >>string1;// entered username
// Check students username validity
userName.find_first_of("checkUserName.txt");
if string1 /found then
cout << "Username not found"<<;
else
ifstream infile("string1.txt", ios::in); //open students file
ifstream infile("markScheme.txt", ios::in);
while (getline(markScheme, line1)) {
if (line1.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line2)) {
if (line2.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line3)) {
if (line3.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line4)) {
if (line4.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line5)) {
if (line5.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line6)) {
if (line6.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line7)) {
if (line7.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line8)) {
if (line8.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line9)) {
if (line9.find(search) != string::npos)
++1 counter;
while (getline(markScheme, line10)) {
if (line10.find(search) != string::npos)
++1 counter;
//Display students mark
cout << "Students mark is (counter)";
}
}
•
•
Join Date: Nov 2004
Posts: 108
Reputation:
Solved Threads: 3
Please use code tags
http://daniweb.com/techtalkforums/an...nouncementid=3
http://daniweb.com/techtalkforums/an...nouncementid=3
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
I'm not surprised you're getting errors. Aside from the odd choice of using so many loops where one will do, you fail to close most of your blocks. Compare this with what you have and do try to learn from it:
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <fstream> #include <iostream> #include <string> using namespace std; int main() { ifstream in("somefile"); string search; string line; int n = 0; if (!in) { cerr<<"Error opening file"<<endl; return EXIT_FAILURE; } cout<<"Enter a search string: "; if (!getline(cin, search)) { cerr<<"Invalid input"<<endl; return EXIT_FAILURE; } while (getline(in, line)) { if (line.find(search) == string::npos) ++n; } cout<< n <<" occurances of "<< search <<" were found"<<endl; return EXIT_SUCCESS; }
New members chased away this month: 4
•
•
Join Date: Feb 2005
Posts: 24
Reputation:
Solved Threads: 0
still having problems using the strings created in the marking scheme being searched for in the students file this is what i have got so far
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
using std::cout;
using std::cin;
using std::ifstream;
int main()
{
string username; //Username that will be searched for
cout << "Marking Program"; //Start of program
cout << "Enter Students Username:"; //Get username off program user
cin >> username;
ifstream in("checkUserName.txt"); //Searching for students username
string search;
string line;
int n = 0;
if (!in) {
cerr<<"Username not found"<<endl; //If entered username not found display
return EXIT_FAILURE; //error message
}
else
if (in){
ifstream in(username.txt); //open students program
}
{ ifstream in("markScheme.txt"); //open the marking scheme file
if (!in){
cerr<<"Mark Scheme not found"<<endl; //If file not found display error
return EXIT_FAILURE;
}
}
if (!getline(cin, search)) {
!=++n;
}
while (getline(in, line)) {
if (line.find(search) == string::npos)
++n;
}
cout<< "students mark is"<<n<<"out of 10"<<endl;
return EXIT_SUCCESS;
}
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
using std::cout;
using std::cin;
using std::ifstream;
int main()
{
string username; //Username that will be searched for
cout << "Marking Program"; //Start of program
cout << "Enter Students Username:"; //Get username off program user
cin >> username;
ifstream in("checkUserName.txt"); //Searching for students username
string search;
string line;
int n = 0;
if (!in) {
cerr<<"Username not found"<<endl; //If entered username not found display
return EXIT_FAILURE; //error message
}
else
if (in){
ifstream in(username.txt); //open students program
}
{ ifstream in("markScheme.txt"); //open the marking scheme file
if (!in){
cerr<<"Mark Scheme not found"<<endl; //If file not found display error
return EXIT_FAILURE;
}
}
if (!getline(cin, search)) {
!=++n;
}
while (getline(in, line)) {
if (line.find(search) == string::npos)
++n;
}
cout<< "students mark is"<<n<<"out of 10"<<endl;
return EXIT_SUCCESS;
}
•
•
Join Date: Feb 2005
Posts: 24
Reputation:
Solved Threads: 0
sorry forgot code tags
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <fstream> #include <iostream> #include <string> using namespace std; using std::cout; using std::cin; using std::ifstream; int main() { string username; //Username that will be searched for cout << "Marking Program"; //Start of program cout << "Enter Students Username:"; //Get username off program user cin >> username; ifstream in("checkUserName.txt"); //Searching for students username string search; string line; int n = 0; if (!in) { cerr<<"Username not found"<<endl; //If entered username not found display return EXIT_FAILURE; //error message } else if (in){ ifstream in(username.txt); //open students program } { ifstream in("markScheme.txt"); //open the marking scheme file if (!in){ cerr<<"Mark Scheme not found"<<endl; //If file not found display error return EXIT_FAILURE; } } if (!getline(cin, search)) { !=++n; } while (getline(in, line)) { if (line.find(search) == string::npos) ++n; } cout<< "students mark is"<<n<<"out of 10"<<endl; return EXIT_SUCCESS; }
![]() |
Similar Threads
- STOP Errors Before AND After Upgrade (Windows NT / 2000 / XP)
- what's the best program to keep pc without errors (Windows NT / 2000 / XP)
- Error in c++ program (C++)
Other Threads in the C++ Forum
- Previous Thread: help with file streaming
- Next Thread: Help referencing variables
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






