Code Errors

i have got this code but im gettin a lot of errors on it can some one tell me where im going wrong im having a huge amount of errors can anyone help me make correct this code
its supposed to read the upper case letters in the file  

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
 ofstream outputFile;
      outputFile.open("proj9.txt");

      cout << "now writing data to a file " << endl;
      outputFile << "Hello My name is 7\n";
      outputFile << "Where Are you From 8\n";
      outputFile << "What are You Doing 7\n";
      outputFile << "How are You Today 9\n";
      outputFile << "I am From Russia 12\n";
      outputFile << "We are Not From Here \n";

      outputFile.close();
       
        char line[200];   // Assuming max. 80 characters per line.
 int k, counter;   // Used to count the # of letters
 ifstream myFile("proj9.txt", ios::in);  // open a file for reading
 if (myfile.fail())
 {
  cerr << "Cannot input file\n";
  return 1;
 }
 while (! myFile.eof())  // loop until end of file is true
 {
  myFile.getline(line, sizeof(line));  // read a line, max. 80 characters
  for (k = counter = 0; line[k]; ++k)
   if (isalpha(line[k]))
    ++counter;
  cout << line << " contains " << counter << " letters\n";
 } // while
 myFile.close();   // close the input file
 return 0;
} // main    
kajumbliesAsked:
Who is Participating?
 
markcjeffreyCommented:
It would be helpful to know exactly what kinds of errors you are having (ex compilation, or algorithm correctness), and what they are.

For now I assume you have correctness errors.

"its supposed to read the upper case letters in the file"
Right now it seems your program is counting _all_ alphabetical characters, upper and lower case.

You could change your for loop with:

 for (k = counter = 0; line[k]; ++k)
   if ( line[k] >= 'A' && line[k] <= 'Z')
    ++counter;

Beyond this, I would need to see the output to know exactly what these errors are.
0
 
kajumbliesAuthor Commented:
ok that's helpful sorry I should have done done that I didn't put them because there are a lot of errors in the program
0
 
kajumbliesAuthor Commented:
I was wondering if it is possible for you to help me ether later tonight or tomorrow do that I ould figure this problem out. I'm at work now but I'll be off at around 12 so if that is possible please let me know  thank you so much
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
markcjeffreyCommented:
It's possible. Either way, posting errors (whether they're output or compilation) will get you better answers, and what output you _expect_ to see in the output.
0
 
kajumbliesAuthor Commented:
these are all the errors i get when i try to run the program

im sorry there are a lot of them  

c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(23) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(23) : error C2065: ' char' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(23) : error C2146: syntax error : missing ';' before identifier 'line'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(23) : error C2065: 'line' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(23) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(23) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C2065: '  ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C2146: syntax error : missing ';' before identifier ' int'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C2065: ' int' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C2146: syntax error : missing ';' before identifier 'k'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C2065: 'k' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C2065: 'counter' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(24) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(25) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(25) : error C2065: '  ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(25) : error C2146: syntax error : missing ';' before identifier ' inFile'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(25) : error C2065: ' inFile' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(25) : error C2228: left of '.open' must have class/struct/union
        type is ''unknown-type''
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(25) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(26) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(26) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(26) : error C2146: syntax error : missing ';' before identifier ' if'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(26) : error C2065: 'inFile' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(26) : error C2228: left of '.fail' must have class/struct/union
        type is ''unknown-type''
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(27) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(27) : error C2146: syntax error : missing ';' before identifier ' '
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(26) : error C3861: ' if': identifier not found
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(27) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(27) : error C2143: syntax error : missing ';' before '{'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(28) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(28) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(28) : error C2146: syntax error : missing ';' before identifier 'cerr'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(29) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(29) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(29) : error C2143: syntax error : missing ';' before 'return'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(30) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(30) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(30) : error C2143: syntax error : missing ';' before '}'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(31) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(31) : error C2065: 'inFile' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(31) : error C2228: left of '.eof' must have class/struct/union
        type is ''unknown-type''
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(31) : error C3861: ' while': identifier not found
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(31) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(32) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(32) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(32) : error C2146: syntax error : missing ';' before identifier ' '
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(32) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(32) : error C2143: syntax error : missing ';' before '{'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C2146: syntax error : missing ';' before identifier 'inFile'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C2065: 'inFile' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C2228: left of '.getline' must have class/struct/union
        type is ''unknown-type''
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C2065: 'line' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C2065: 'line' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C2070: ''unknown-type'': illegal sizeof operand
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(33) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(34) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(34) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(34) : error C2146: syntax error : missing ';' before identifier ' '
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(34) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(34) : error C2146: syntax error : missing ';' before identifier 'inFile'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(34) : error C2065: 'inFile' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(34) : error C2228: left of '.assign' must have class/struct/union
        type is ''unknown-type''
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(34) : error C2065: 'line' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C2143: syntax error : missing ';' before 'for'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C2065: 'k' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C2065: 'counter' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C2065: 'k' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C2065: 'line' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C2228: left of '.size' must have class/struct/union
        type is ''unknown-type''
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(35) : error C2065: 'k' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C2065: '  ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C2143: syntax error : missing ';' before 'if'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C2065: 'line' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C2228: left of '.at' must have class/struct/union
        type is ''unknown-type''
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C2065: 'k' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C2065: 'line' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C2228: left of '.at' must have class/struct/union
        type is ''unknown-type''
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(36) : error C2065: 'k' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(37) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(37) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(37) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(37) : warning C4390: ';' : empty controlled statement found; is this the intent?
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(37) : error C2065: '   ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(37) : error C2146: syntax error : missing ';' before identifier 'counter'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(37) : error C2065: 'counter' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(38) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(38) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(38) : error C2146: syntax error : missing ';' before identifier 'cout'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(38) : error C2065: 'line' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(38) : error C2065: 'counter' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(39) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(39) : error C2065: ' ' : undeclared identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(39) : error C2143: syntax error : missing ';' before '}'
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(40) : error C3872: '0xa0': this character is not allowed in an identifier
c:\users\constantine\documents\visual studio 2008\projects\assignment9\assignment9\assignment9.cpp(40) : fatal error C1003: error count exceeds 100; stopping compilation
Build log was saved at "file://c:\Users\Constantine\Documents\Visual Studio 2008\Projects\Assignment9\Assignment9\Debug\BuildLog.htm"
Assignment9 - 102 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
0
 
pkadianCommented:
Small Mistake.
At line 23 you are using variable name 'myfile' , where as your declared variable is 'myFile'.

There is upper F in variable name , replace 'myfile' with 'myFile' and hopefully all would be resolved.
Rest all are seems to be because of one error only.
0
 
pkadianCommented:
I can compile the code successfully.
:)
0
 
kajumbliesAuthor Commented:
that worked great how would i add up the letters that i counted and how would i display the letter that are in capital letters  
0
 
kajumbliesAuthor Commented:
would this code display all the uppercase letters

 char line[81];   // Assuming max. 80 characters per line.
 string  myline;
 int   k, counter;   // Used to count the # of letters
 ifstream myFile("proj9.txt", ios::in);  // open a file for reading
 if (myFile.fail())
 {
  cerr << "Cannot input file\n";
  return 1;
 }
 while (! myFile.eof())  // loop until end of file is true
 {
  myFile.getline(line, sizeof(line));  // read a line, max. 80 characters
  myline.assign(line);
  for (k = counter = 0; k < myline.size(); ++k)
   if (toupper(myline.at(k)) >= 'A' && toupper(myline.at(k)) <= 'Z')
    ++counter;
  cout << myline << " contains " << counter << " letters\n";
 } // while
 myFile.close();   // close the input file
 return 0;
} // main       
0
 
pkadianCommented:
To add up , make new variable to get addup of 'counter' , in while loop.
And to Disply capitals , make new char string and get all capitals concatenated into string and display both add up and capitals after while loop.
0
 
pkadianCommented:
No , Whatever touppar is rturning , you need to store in myline.at(k).
That means you need to chnage the case as well store back the uppar case in same location.
0
 
pkadianCommented:
Also I think you can close one of the case , as you are having one issue resolved and now asking same question on both the questions.
0
 
kajumbliesAuthor Commented:
thanks so much
0
 
pkadianCommented:
I feel  the solution was to resolve the compilation errors.As it worked by my solution. Not sure how the accepted solution is have relevence with question.Please Review
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.