minor error need help on

This is a discussion on minor error need help on within the C++ Programming forums, part of the General Programming Boards category; Code: #include <ctype.h> #include <iomanip.h> #include <fstream.h> #include <string> #include <iostream.h> void printdata(char, double); int main (void) { int freqcount[26] ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    16

    minor error need help on

    Code:
    #include <ctype.h>
    #include <iomanip.h>
    #include <fstream.h>
    #include <string>
    #include <iostream.h>
    
    void printdata(char, double);
    
    int main (void)
    {
    int freqcount[26] = {0};  //array to hold letter values
    int totalcount = 0;       //initializes total count to value '0'
    string InFileName;
    cout <<"\nEnter name of file to process: "; //prompts user for input filename
    getline(cin,InFileName); 
    ifstream inStream;inStream.open(InFileName.data());
    if (!inStream.is_open())
    {
      cerr << "\nError opening " << InFileName << endl;
      return -1;
    }
    double percent;                  
    double i;
    char Ch;
    inStream >> Ch;
    while (!inStream.eof())
    {
     Ch = toupper(Ch);
     if ((Ch <= 'Z') && (Ch >= 'A'))
      { 
       totalcount++;
       freqcount[Ch - 65]++;
      }
     inStream >> Ch;
    }
    cout << "\n" << "Char       %" << endl
    << "===================================================================\n";
    for (int k=0; k<=25; k++)
     {
      percent = freqcount[k]*100.0/totalcount;
      printdata(char(k+65), percent);
     }
    cout << endl << endl << "Number of letters = " << totalcount << endl;
    }
    
    void printdata(char Ch, double percent)
    {
    double i;
    cout << "  "<< Ch << "       " << setiosflags(ios::showpoint | ios::fixed
           | ios::right) << setprecision(1) << setw(5) << percent;
    for (i=2*percent; i>0.5; i--) cout << '*'; cout << endl;
    }
    and my errors are as follows

    test.c: In function 'int main()':
    test.c:13: error: 'string' undeclared (first use this function)
    test.c:13: error: (Each undeclared identifier is reported only once for each function it appears in.)
    test.c:13: error: parse error before ';' token
    test.c:15: error: 'InFileName' undeclared (first use this function)

    any help would be appreciated.

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    might be beaten to this but here goes...

    Code:
    #include <ctype.h>
    #include <iomanip>
    #include <fstream>
    #include <string>
    #include <iostream>
    
    using namespace std;

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Code:
    #include <ctype.h>
    Should be:
    Code:
    #include <cctype>
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    You might need a
    Code:
    cin.get()
    as well near the end of main to pause the program.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    16
    i still get the same errors.

  6. #6
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Try compiling in .cpp

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    16
    thank you for all of the advice i got it to work.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21