Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help

Options
  • 23-01-2008 12:55am
    #1
    Closed Accounts Posts: 11


    I'm a noob to c++ and programing altogether.

    I have this program that i wrote but i cannot get it to work properly.
    It is supposed to get imput from a file( user defined) , the put it into an array, print the array backwards. Then rotate the contents of the array wrapping the last digit around to the first position. Thanks!




    #include <iostream>
    #include <fstream>
    using namespace std;
    
    void main()
    {
        //state varibles
        int fname;
        int headernum;
        const int MAX = 100;
        int num[MAX];
        int i;
        int save;
        char choice;
        int rotate
    
        //get file name
        cout << "What is the file name" << endl;
        cin >> fname;
    
        //open file
        ifstream inFile;
        inFile.open(fname);
        if(!inFile)
        {
            cout << "Error opening file" << fname << endl;
            exit(1);
        }
    
        //read header number
        inFile >> headernum;
        if(headernum>MAX)
        {
            cout << "Error: to many numbers";
            exit(1);
        }
        //first loop
        for(i<headernum,i=0;i++)
        {
            inFile >> num[i];
        }
        
        //reverse print
        for(1>=0;i--)
        {
            cout << num[i];
        }
        
        cout << "rotate?     y/n" << endl;
        cin >> rotate;
        if(rotate = y)
        {
        //rotate loop
        for(rotate = y)
        {
            save = headernum-1;
            for(i<headernum,i=2;i++)
            {
                num[headernum-i-1] = num[headernum-i];
            }
            num[0] = save;
            cout << num;
            cout << endl; << "rotate again    y/n";
            cin >> rotate;
        }
        
        }
        else
            exit(1);
    }
    


Comments

  • Registered Users Posts: 26,558 ✭✭✭✭Creamy Goodness


    what's going wrong?

    also wrap code in [.code] [./code] (minus the .) as it allows for identation and easier to read.


  • Closed Accounts Posts: 11 Qin


    The compiler is giving me the error
    : error C2664: 'void std::basic_ifstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'int' to 'const wchar_t *'
    1>        with
    1>        [
    1>            _Elem=char,
    1>            _Traits=std::char_traits<char>
    1>        ]
    


    there is also 6 cases of no semicolons before some of the for loops and an if statement but i checked all of them and they look ok to me.

    Just and overall fail of the program, it wont compile and run at all.

    plz help


  • Registered Users Posts: 413 ✭✭ianhobo


    Why do the 6 semi colon errors look fine to you?
    Compare line 14 with line 15
    Line 14:
    char choice;
    
    Line 15:
    int rotate
    

    Notice anything?

    Did you write this completly before you tried to compile it the first time?

    Some comments first, all your variables that you have declared at the beginning are un-initialised. THis is poor programming practice
    int fname;
    
    This should be
    int fname=0;
    

    Your cin statement, is that correct? What are you hoping to achieve here
     cout << "What is the file name" << endl;
     cin >> fname;
    
    Because you have declared fname as an int, and its unlikely you will be able to hold a "normal" filename here

    Again, you first for loop. there is a semi colon issue there. re-write it on a piece of paper and compare that to your code

    Also, look over the differnce between assignment and comparison with the '='

    If you do that, your program *should?* compile (well maybe almost)


    Oh yeah, and that big error you posted has something to do what I said about the filename. Filenames tend to be more just a number, either a string, or a char array


  • Closed Accounts Posts: 11 Qin


    Ill try that...
    thanks.


Advertisement