954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Days Out

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

janito2008
Newbie Poster
6 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

ok, what do you have so far

campkev
Posting Pro in Training
484 posts since Jul 2005
Reputation Points: 14
Solved Threads: 19
 

Procrastinated until the bitter end, eh? :)

agiorgio
Newbie Poster
15 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

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.

janito2008
Newbie Poster
6 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

//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 average number
//of days absent for all employees.
#include > 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:

janito2008
Newbie Poster
6 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

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
#include
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 <

janito2008
Newbie Poster
6 posts since Feb 2006
Reputation Points: 10
Solved Threads: 0
 

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 <
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.

Bench
Posting Pro
577 posts since Feb 2006
Reputation Points: 307
Solved Threads: 63
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You