Program with many errors

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 24
Reputation: jonnie83 is an unknown quantity at this point 
Solved Threads: 0
jonnie83 jonnie83 is offline Offline
Newbie Poster

Program with many errors

 
0
  #1
Feb 17th, 2005
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)";

}

}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: Program with many errors

 
0
  #2
Feb 18th, 2005
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Program with many errors

 
0
  #3
Feb 18th, 2005
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:
  1. #include <cstdlib>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. ifstream in("somefile");
  11. string search;
  12. string line;
  13. int n = 0;
  14.  
  15. if (!in) {
  16. cerr<<"Error opening file"<<endl;
  17. return EXIT_FAILURE;
  18. }
  19.  
  20. cout<<"Enter a search string: ";
  21. if (!getline(cin, search)) {
  22. cerr<<"Invalid input"<<endl;
  23. return EXIT_FAILURE;
  24. }
  25.  
  26. while (getline(in, line)) {
  27. if (line.find(search) == string::npos)
  28. ++n;
  29. }
  30.  
  31. cout<< n <<" occurances of "<< search <<" were found"<<endl;
  32.  
  33. return EXIT_SUCCESS;
  34. }
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 24
Reputation: jonnie83 is an unknown quantity at this point 
Solved Threads: 0
jonnie83 jonnie83 is offline Offline
Newbie Poster

Re: Program with many errors

 
0
  #4
Feb 21st, 2005
Thanks for your help, I really was stuck
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 24
Reputation: jonnie83 is an unknown quantity at this point 
Solved Threads: 0
jonnie83 jonnie83 is offline Offline
Newbie Poster

Re: Program with many errors

 
0
  #5
Feb 24th, 2005
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;
}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Program with many errors

 
0
  #6
Feb 24th, 2005
>still having problems
Can you be more specific?
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 24
Reputation: jonnie83 is an unknown quantity at this point 
Solved Threads: 0
jonnie83 jonnie83 is offline Offline
Newbie Poster

Re: Program with many errors

 
0
  #7
Feb 24th, 2005
sorry forgot code tags

  1. #include <cstdlib>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7. using std::cout;
  8. using std::cin;
  9. using std::ifstream;
  10.  
  11. int main()
  12. {
  13. string username; //Username that will be searched for
  14.  
  15. cout << "Marking Program"; //Start of program
  16.  
  17. cout << "Enter Students Username:"; //Get username off program user
  18. cin >> username;
  19.  
  20. ifstream in("checkUserName.txt"); //Searching for students username
  21. string search;
  22. string line;
  23. int n = 0;
  24.  
  25. if (!in) {
  26. cerr<<"Username not found"<<endl; //If entered username not found display
  27. return EXIT_FAILURE; //error message
  28. }
  29. else
  30. if (in){
  31. ifstream in(username.txt); //open students program
  32. }
  33.  
  34.  
  35.  
  36.  
  37. { ifstream in("markScheme.txt"); //open the marking scheme file
  38. if (!in){
  39. cerr<<"Mark Scheme not found"<<endl; //If file not found display error
  40. return EXIT_FAILURE;
  41. }
  42. }
  43.  
  44.  
  45.  
  46. if (!getline(cin, search)) {
  47. !=++n;
  48. }
  49.  
  50. while (getline(in, line)) {
  51. if (line.find(search) == string::npos)
  52. ++n;
  53. }
  54.  
  55. cout<< "students mark is"<<n<<"out of 10"<<endl;
  56.  
  57. return EXIT_SUCCESS;
  58. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 24
Reputation: jonnie83 is an unknown quantity at this point 
Solved Threads: 0
jonnie83 jonnie83 is offline Offline
Newbie Poster

Re: Program with many errors

 
0
  #8
Feb 24th, 2005
yeah what i want the program to do is use the strings i've created in the markScheme.txt to see if they are in the students file that I open. Does that make sense!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,847
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 753
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Program with many errors

 
0
  #9
Feb 24th, 2005
It makes perfect sense. What I want to know is what the program you have is doing that fails to meet your expectations.
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 24
Reputation: jonnie83 is an unknown quantity at this point 
Solved Threads: 0
jonnie83 jonnie83 is offline Offline
Newbie Poster

Re: Program with many errors

 
0
  #10
Feb 24th, 2005
Once a string is found (10 in total) i want it to increment the counter then output the final mark to the program user
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC