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
  • 31-01-2008 8:23am
    #1
    Closed Accounts Posts: 11


    I have this program I wrote for my CS2 class. It is suposed to read input from a file. Then store it it the appropriate array. outputting the content from parallel arrays. then let the user use a liner search to find an id.

    kind of like an employee time system.

    well the trouble is that my compiler doesn't work. im trying to use textpad with borland. but the paths are all messed up and cant seam to get em right. this was due yesterday, so if any one could make sure it compiles ,and mabey do some debuging while your at it, the send word to me.

    the input file that it is reading looks like this
    3
    11254 12
    15478 40
    12345 45
    

    the code i wrote is as follows
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    void main()
    {
        const int MAX = 100;
        char fname[MAX];
        cout << "what is the file name? :";
        cin >> fname;
        ifstream infile;
        infile.open(fname);
        if(!infile){
            cout << "file, " << fname << " , not found" << endl;
            exit(0);
        }
        else{
            cout << "opening" << endl;
        }
    
        const int MAXX=10;
        int head = 0;
        infile >> head;
        if(head > 10 ){
            cout << "file " << fname << " has to many employees";
            exit(0);
        }
        int Id[MAXX];
        int Hours[MAXX];
    
        for(i=0,i<head;i++){
            infile >> Id[i] >> Hours[i];
        }
        for(i=0, i<head; i++)
        {
            cout << "employee" << Id[i] << "worked";
            if(Hours[i]<40){
                cout << Hours[i] << "partime hours";
            }
            else if(Hours[i]==40){
                cout << Hours[i] << "fulltime hours";
            }
            else if(Hours[i]>40){
                cout << Hours[i] << "40 fulltime hours and " << Hours[i] - 40 << "overtime hours";
            }
            cout << endl;
        }
        int key;
        cout << "enter employee ID #" << endl;
        cin >> key;
        int index = 0;
        for(i=0, i < head; i++){
            if(Id[i] == key){
                index=i;
                break;
            }
        }
        cout << "employee" << Id[index] << "worked";
        if(Hours[index] == 40){
            cout << " 40 fulltime hours "<< endl;
        }
        else if(Hours[index] > 40){
            cout << Hours[index]-40 << " overtime hours " << endl;
        }
        else if(Hours[index] < 40){
            cout << Hours[index] << " partime hours " << endl;
        }
    
    
    
    
    }
    

    Please hurry to respond. im already late.

    thanks for your help


Comments

  • Registered Users Posts: 2,082 ✭✭✭Tobias Greeshman


    I don't believe you've been made aware of the homework policy on here, have you?

    In short we don't do other peoples homework.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    That's right we don't. Qin try posting any error messages you're getting when you try to compile, we might be able to help you then. You will of course have to start a new thread as this on is now locked.


This discussion has been closed.
Advertisement