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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.