Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

//Help

  • 31-01-2008 07: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, Registered Users 2 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, Registered Users 2 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