Thread: Can someone help me with this .cpp file ples

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Can someone help me with this .cpp file ples

    <<< split from dead thread error: expected unqualified-id before "while" (???) >>>
    Can someone help me with this .cpp file ples

    Code:
    #include <iostream>
    #include <fstream> // for file input/output
    #include <vector> // for the vector container
    using namespace std;
    
    ifstream fin("text.txt"); // ifstream -> input file stream
    
    char ch; // used to read the dots
    int num; // used to read the numbers
    vector<int> sums; // vector container for ints;
    int counter=0; // used for .... counting
    while(!fin.eof());// while we haven't 
    //reached the eof (end of file)
    {
    sums.push_back(0); // add a new element to the vector
    // with initial value 0
    for(int i=0;i<3;i++) // go through the three numbers
    {
    fin >> ch >> num; // load the dot and then the
    // number
    sums[counter]+=num; // add the three numbers
    }
    counter++; // increase the counter
    }
    fin.close(); // remember to close the file
    
    // finding the mode
    int frequency[500]; // 1
    for(int i=0; i<500; i++)
    frequency[i]=0; // 2
    vector<int>::iterator it; // 3
    for(it=sums.begin();it<sums.end();it++) // 4
    frequency[*it-500]+=1; // 5
    int mode=0; // 6
    for(int h=0; h<500; h++) // 7
    if(frequency[h]>mode)
    mode=h;
    mode+=500; //8
    cout << "nmode: " << mode << "nn";
    
    // getting the proper ascii
    ofstream fout("text2.txt");
    int subtract=mode-??; // subtract = the password
    for(int i=0;i<sums.size();i++) // no iterators this time
    {
    sums[i]-=subtract; // get proper ascii numbers
    cout << sums[i]; // print out message
    fout << sums[i]; // save message to a text file
    }
    fout.close(); // close the file
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    while loops need to be inside the body of a function.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    reply

    do u think u could fix it for me please

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    I could, but I won't. You're the one who needs to learn the basics of C++, and you won't achieve that if I simply fix your code for you.

    I've told you what the problem is (or, more specifically, the problem you asked about - there are others).

    If you can't be bothered buying a basic textbook, google for "C++ basic tutorial". Read through what you find - from the beginning - BEFORE trying to write code again.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    reply

    true . but i would rather have u do then learn from ur skills
    lol

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Get a book.
    And indent your code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > but i would rather have u do then learn from ur skills
    Nobody learns how to cook simply by eating at lots of restaurants.

    If you want to learn, then make an effort.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading from file stream
    By shmitson in forum C Programming
    Replies: 0
    Last Post: 04-05-2011, 04:37 PM
  2. Memory Leak in AppWizard-Generated Code
    By jrohde in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2010, 04:24 PM
  3. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  4. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM