Please HELP!!

This is a discussion on Please HELP!! within the C++ Programming forums, part of the General Programming Boards category; Im new to programming but i take ok notes, my largest and smallest functions are not working but im not ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    6

    Please HELP!!

    Im new to programming but i take ok notes, my largest and smallest functions are not working but im not getting errors and i also have to print out a list of all the employees at the end ot entering them in the format all the way at the bottem thoes 3 things arent working please someone help me.
    Code:
    #include <iostream.h> 
    
    
    const int SIZE=10000; 
    void EMPID (int& EmployeeID);  
    void Trip (int &Trips); 
    void Mileage (int Trips, double Miles[SIZE],int EmployeeID, double COST,
    double 
    &TOTAL_SUM, double & Total, double &Total_Miles, double A); 
    float Cost (int Trips, double Miles [SIZE], double & COST, double 
    TOTAL_SUM,double A); 
    void LINE (); 
    void LARGEST_TRIP (double COST, double & A); 
    float SMALLEST_TRIP (double COST); 
    void IndivResults (int Trips, double Miles[SIZE], double COST, double
    TOTAL_SUM, 
    int EmployeeID, double Total, double A, double Total_Miles); 
    void Totals (); 
    void main () 
    { 
    
    int EmployeeID; 
    EMPID(EmployeeID); 
    
    } 
    //------------------------------------------------------------------- 
    void EMPID (int& EmployeeID)  
    { 
    int Trips=0; 
    double Miles [SIZE];  
    double COST=0; 
    double TOTAL_SUM=0;  
    double Total=0; 
    double A=0; 
    double Total_Miles=0; 
    
    
    cout << "Employee ID or 0 to end program" << endl; 
    cin >> EmployeeID; 
    if (EmployeeID < 0)  
    {cout << "PLEASE ENTER A VALID EMPLOYEE ID NUMBER GREATER THAN 0." << endl; 
    cin >> EmployeeID; 
    } 
    if (EmployeeID==0) 
    {Totals(); 
    } 
    if (EmployeeID >= 1) 
    { 
    Trip(Trips); 
    Mileage(Trips,Miles,EmployeeID,COST, TOTAL_SUM,Total,Total_Miles,A); 
    SMALLEST_TRIP (COST); 
    LARGEST_TRIP (COST,A); 
    LINE(); 
    IndivResults (Trips, Miles, COST, 
    TOTAL_SUM,EmployeeID,Total,A,Total_Miles); 
    LINE(); 
    } 
    } 
    
    
    //------------------------------------------------------------------- 
    void Trip (int &Trips) 
    { 
    
    
    cout << "Enter the Number of Trips  "; 
    cin >> Trips; 
    if (Trips < 0)  
    {cout << "Trips must be greater than or equal to 0." << endl; 
    cin >> Trips; 
    } 
    
    
    
    
    } 
    
    //------------------------------------------------------------------- 
    void Mileage (int Trips, double  Miles[SIZE],int EmployeeID , double COST, 
    double & TOTAL_SUM, double  & Total, double &Total_Miles,double A) 
    { 
    
    for (int i=0; i < Trips; i++) 
    { 
    cout << "Enter the Mileage  "; 
    cin >> Miles[i]; 
    if (Miles[i] < 0)  
    {cout << "Mileage must be greater than or equal to 0." << endl; 
    cin >> Miles[i]; 
    } 
    
    Total_Miles += Miles[i]; 
    TOTAL_SUM = Miles[i]; 
    Cost(Trips,Miles,COST,TOTAL_SUM,A); 
    
    cout << "Employee "<< EmployeeID << " Cost for the mileage of " << Miles[i]
    << 
    "is" << Cost(Trips,Miles,COST,TOTAL_SUM,A) << endl;    
    
    Total += COST; 
    } 
    } 
    
    
    //------------------------------------------------------------------- 
    float Cost (int Trips, double Miles [SIZE],double & COST, double 
    TOTAL_SUM,double A) 
    { 
    const float First_Range = 1; 
    const float Second_Range = 2000; 
    const float First_Rate= .12; 
    const float Second_Rate= .10; 
    const float Base_Charge = 2; 
    
    
    
    
    
    if ((TOTAL_SUM >= First_Range) && (TOTAL_SUM < Second_Range)) 
    {COST = (First_Rate * TOTAL_SUM) + (Base_Charge); 
    } 
    
    if ((TOTAL_SUM >= Second_Range))  
    {COST = ((TOTAL_SUM - Second_Range) * (Second_Rate)) + (Second_Range * 
    First_Rate) + (Base_Charge);  
    } 
    
    
    return COST; 
    } 
    
    
    //------------------------------------------------------------------- 
    void LINE () 
    { 
    cout << "---------------------------------------------" << endl; 
    
    } 
    //------------------------------------------------------------------- 
    void LARGEST_TRIP (double COST, double &A) 
    { 
    A=0; 
    if (COST >= A)  
    { 
    A=COST; 
    } 
    } 
    //------------------------------------------------------------------- 
    float SMALLEST_TRIP (double COST) 
    { 
    double B=1000000; 
    if (COST<= B)  
    {B=COST; 
    } 
    return B; 
    }  
    //------------------------------------------------------------------- 
    void IndivResults (int Trips, double Miles[SIZE], double COST, double
    TOTAL_SUM, 
    int EmployeeID, double Total, double  A, double Total_Miles) 
    { 
    cout.setf (ios::fixed); 
    cout.precision (2); 
    
    
    
    cout << "Total Cost for Employee  "<< EmployeeID << "   is    " << Total
    << 
    endl; 
    cout << "Number of trips for employee  " << EmployeeID<<"  is 
    "<<Trips<<endl; 
    cout << "Average dollar trip for employee  " << EmployeeID<< "  is  " << 
    Total/Trips <<endl; 
    cout << "Average mileage trip for employee  " << EmployeeID << "  is  " 
    <<Total_Miles/Trips <<endl; 
    cout << "The smallest charge is" << SMALLEST_TRIP(COST) << endl; 
    cout << "The largest dollar cost for employee " << EmployeeID << "  is  " <<
    A 
    << endl;  
    
    cout<<endl<<endl; 
    main(); 
    } 
    //-------------------------------------------------------------------- 
    void Totals () 
    { 
    
    cout << "Total Cost for all employees is " << endl; 
    cout << "The total number of trips is "  << endl; 
    cout << "The total miles for all the trips is" << endl; 
    cout << "The number of Employees is" << endl; 
    cout << "The average cost per employee is " << endl; 
    cout << "The average cost per trip is " << endl; 
    cout << "The average miles per trip is "<< endl; 
    cout << "The largest cost of an employee trip is "<<endl; 
    cout << "The smallest cost of an employee trip is " << endl; 
    }

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    you're just outputting text in Totals, but not actually outputting any totals. thats from a quick look, i'll see if i can look over it a bit later.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    There are a couple of things that have to be said about this program. First of all the total function does absolutely nothing but output a couple of line of text. There are no variables involved...
    Second the way it is organized makes very little sense to me. You say you want to output of multiple employess, yet you make only one of every variables allowing there to only exist data for one employee at a time. I think you would have to rethink the entire design of your program. Namely i would make a employee struct for the easy managing of data if you really intend to keep data on multiple employees. Further it would be smart to divide the program in a different order. Consider the following psuedo code:

    Code:
    start
    
    loop while users wishes to add new employees
            get input for employee
                    Functions for specifit values
    end loop
    
    loop through all employess
            output employee data
    end loop
    
    end

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    I have a couple style comments that might help you debug and maintain your projects. First of all, that big list of function protos at the very beginning of your code seems pretty messy and unorganized. Why do you use void main()? If you're doing it to save yourself from one little line of code, don't bother. The ISO C++ standard of 1997 says that int main() doesn't have to have return 0; at the end(assuming your compiler is compliant). Try using encapsulation mechanisms like structures and objects to better organize your code. I don't know if you felt like this working on this program, but the function-after-function-after-function method gets very cumbersome. You could try splitting up related functions into different source code files. Try separating non-related statements(eg two statements that would not represent the same idea in pseudocode) with empty lines. Also, variable/function names in all caps generally implies that the function/var is a macro. Try to get rid of some of the smaller funcitons that consist of one line of code. So basically, the point I am trying to get across here is code organization and control. That program of yours looks like a nightmare to modify, and it is really not all that complex. I am not trying to be insulting, just helpful. Hope that stuff makes your life easier in the future.

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    couldn't agree with Porky more =] i was goin to start looking over your code in detail and fix some stuff but after i was tryin to get into a nice format for about 10 mins i didn;t feel like doin lookin at it anymore =/.

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