I need help with a program for school. I have to write a program that asks for the number of days each employee is absent, the total number of days absent for all employees combined and the average number of days absent for all employees combined. I need help before 9:00am tomorrow monrning. :confused:

Thank you in advance for hour much needed help!


janito2008

Recommended Answers

All 6 Replies

ok, what do you have so far

Procrastinated until the bitter end, eh? :)

No I didn't procrastinate to the bitter end. I've been working this assignment since she gave it us on Wednesday, February 15, 2006.

//This program asks for the number of days each employee
//was absent during the past year, the total nunber of
//days absent for all employees and the averagenumber
//of days absent for all employees.

#include <iostream)
using namespace std;

//getdata gets the data by using call by reference
//nothing is returned nor do you need to give it values
void getdata(float *employee1, float employee2, float employee3, float employee4, 
float days, float total employees, float total days, float average)
{
    cout << "Enter employee1 days absent";
    cin >> days absent;

I have more at home. I forgot to bring my book to work with me today. Hopefully my computer is fixed and I can get online tonight and give you what I have at home. PRAY FOR ME :confused:

My computer wasn't ready last night and I couldn't post the remainder of the what I had at home. As I explained yesterday I left my book at home yesterday. I brought it to work with me today, because I had class today. However, we didn't have to turn it in today. Below is the remainder of what I had at home. HELP!!

//This program asks for the number of days each employee
//is absent, the total combined number of days abasent for all employees
//and the average number of days absent for all employees in the past year.
#include <iostream>
#include <iomanip>
using namespace std;

//getdata gets the days absent by using call by reference
//nothing is returned, nor do hyou need to give it values.
void getdata (float *days out, float *total, float *average, char name[40])
{
    cout << "enter name ";
    cin >> name;
    cout << "enter days absent ";
    cin >> days absent;
    if (argc > 1)
    {
        cout << "Total:\n";
        for (int count = 1; count < argc; count++)
            cout << argv[count] << endl;
}

//Calculatetotal takes as parameters, float days and returns the combined total
//--also as a float.
float calculattoal(float(total)
{
    return total;
}
//calcaverage taakes the combined total and divides it by the total number of employees
//and returns the average. Total and average are both float
float calcaverage(float total)
{
    float average
    average=total/employees;
    return(total);
}
//outputvalues takes employees, number of days absent, combined total number of
//days absent and the average of the combined total number of days absent and
///prints them. It does not return any values.
void outputvalues (char name[], float total, average)
{
    cout <<name<< "days absent"<<total<<" total and "<<average<<" average"<<endl;
}
int main()
{
    char name [40]
    float days, total, average;
    getdata(&days, &total, &average);
    for (int count = 1; count < argc; count++)
        cout << argv[count] << endl;
    total=calculatetotal(days);
    average=calcaverage(total);
    putputvalues(name, days, total, average);
    system("pause");
    return 0;
}

I have to put in two input validations. I don't need you to write the program for me. I just need some ideas on how to write it.

This isn't essential, but I'd recommend using "double" instead of "float" - the reason being that float has very low precision... you may end up with your results being incorrectly rounded... double means "double precision" - which is much more accurate

//getdata gets the days absent by using call by reference
//nothing is returned, nor do hyou need to give it values.
void getdata (float *days out, float *total, float *average, char name[40])

"days out" is not a valid variable name, you can't use spaces. call it something like DaysOut or days_out instead.

{
cout << "enter name ";
cin >> name;
cout << "enter days absent ";
cin >> days absent;

again - "days absent" is an error - there's a space in it. Also, you didn't call it "days absent", you called it "days out"

if (argc > 1)
{
cout << "Total:\n";
for (int count = 1; count < argc; count++)
cout << argv[count] << endl;
}

I don't know why you are doing this, but OK.

float calculattoal(float(total)

Take away the second curvy bracket ( - it should read (float total)

float calcaverage(float total)
{
float average
average=total/employees;
return(total);
}

Are you sure you want to return total? I think you want to return average.

void outputvalues (char name[], float total, average)
{
cout <<name<< "days absent"<<total<<" total and "<<average<<" average"<<endl;
}

instead of using char* and char[] for strings of text, use the C++ 'string' type - you might find it makes your life MUCH easier. (For a start - you would not have to specify the length with a C++ string, that happens automatically)

int main()
{
char name [40]
float days, total, average;
getdata(&days, &total, &average);
for (int count = 1; count < argc; count++)
cout << argv[count] << endl;
total=calculatetotal(days);
average=calcaverage(total);
putputvalues(name, days, total, average);
system("pause");
return 0;
}

I have to put in two input validations. I don't need you to write the program for me. I just need some ideas on how to write it.

input validations for what exactly? what criteria are you comparing your input with?

overall, the code you pasted has quite alot of typing errors and 'bad' variable names - fix those first and make it compilable before you go any further.


Also, your "getdata" function accepts pointers and passes by address - This is OK, but you should know what you are doing with pointers before doing this (And looking at your function, you are not treating them like pointers). A much better way is to use references.

So, This....

void getdata (float *days out, float *total, float *average, char name[40])

can change to

void getdata (float &days_out, float &total, float &average, char name[40])

and when you call getdata() from main, you do not need to add the ampersand '&' for the values you send.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.