#include <iostream>
#include <fstream>usingnamespace std;
//Function prototypes
int numberEmployees();
int numberDays(int);
double averageDays(int, int);
int main()
{
//Declaring variables
int employees;
int total;
double average;
ofstream output;
//Function call for first function
employees = numberEmployees();
//Function call for second function
total = numberDays(employees);
//Function call for last function prototype
average = averageDays(employees, total);
//Performing output by main function
cout<< "The average number of days a company's employees are absent is: " <<average<<endl;
output.open("C:\\CS140\\Project 3\\output.txt");
system("pause");
return 0;
}
//Function header for number of employees
int numberEmployees()
{
int workers;
cout<<"Enter the number of employees in the company: ";
cin>>workers;
//Input validation
while(workers<=1)
{
cout<<" Do not accept number less than 1. Please, enter again: ";
cin>>workers;
}
return workers;
}
//Function header for the number of days
int numberDays(int w)
{
int workers = w;
int total = 0;
int absent;
//Creating a loop for every employees' missed days
for (int count=0; count<workers; count++)
{
cout <<"Enter the number of days each employee missed during past year: "<<count+1<<endl;
cin >>absent;
total+=absent;
//Input Validation
while (absent<0)
{
cout<<"Please, do not enter negative number! Try again: ";
cin>>absent;
}
}
return total;
}
//Function header for average number of days absent
double averageDays (int work, int totl)
{
int w = work;
int t = totl;
double aver;
aver=(w*365)/t;
return aver;
}
I don't see the output file when I navigate to my C:\ drive. I have also tried refining my search to "output". still no luck. any suggestions ? Have I placed the code in the right area ?
When opening the file, I would just do 'output.open("output.txt");'. It should automatically save to the location of where your project is saved. And your not actually putting anything into the file, your just creating an empty one.
So I was just reading your code, before I run it, I want to ask you what are you trying to output to the file?, at the end I see that you are opening a file, but you are not trying to write to the file anywhere.
for example I didn't see anything like:
output << average;
and to make sure things save, you might want to close the file after you write to it to save changes etc.
output.close();
let me know what you are trying to write, or if that works, then I will run it
Hey ! It works ! Thank You :)
I have included both output << average; and output.close;
I have the average as an output text file Now. Do you know how would I be able to have the entire console on the txt file ?