Hey guys below is my full code of the program I am trying to run. I want to save the data automatically. It goes through many areas but the save area is not working for some reason. Errr...I have spent many hours and it is very basic code probably because I use a while statement instead of a cin or cout statement. If you can help that is awesome! I am a beginner and doing this for school have the dietzel book which is crap.
This program grabs employee information for a business and saves the file. It then can create employees and further more. I tryed keeping it very organized to easily read!
Thanks All!
p.s. I had a file made as "a" in my C:// file, but had to change it to a .txt file to save the information. Please not that a file has to be saved in the C:// file to search for the information or folder. The folder has lines of numbers to simulate the information.
///////////////////////////////////////////////////////////////////////////////
// File Name : FinalProject.c
//
// Programmer : Eric Smith
//
// Instructor :
//
// Course : ECET 264-
//
// Date Due : April 20, 2009
//
// Platform : IBM PC (Windows XP)
//
// Compiler : Microsoft Visual C++ 6.0
///////////////////////////////////////////////////////////////////////////////
// Eliminate deprecation warnings for the older, less secure functions
// Needed for Microsoft Visual Studio 2005 and 2008 (Visual C++ Version 8 & 9)
#define _CRT_SECURE_NO_DEPRECATE
// Compiler Includes
#include <math.h>
#include <stdio.h>
#include <stdlib.h> //used for clear screen and pause command
#include <string.h>
// Using Directives & Declarations
// Project Includes
// Constants
#define TRUE 1
#define FALSE 0
#define MAX_SIZE 40
// User Defined Types
// Function Prototypes
int GetSelection (void);
void GetInput (char Name[], double E_Data[]);
void SaveData (char Name[], double E_Data[]);
void ReportFile (double E_Data[]);
void editEmployee (double E_Data[]);
void enterHours (double E_Data[]);
///////////////////////////////////////////////////////////////////////////////
// Function Name : main
//
// Originated : April 20, 2009
//
// Abstract :
//
// Parameters : No input parameters, but has an output parameter of an int
//
// Return Value : none
//
// Misc. I/O : na
//
// Revisions : none
///////////////////////////////////////////////////////////////////////////////
void main (void) {
// Local Variables
int selection = 0;
double E_Data[MAX_SIZE] = {0};
char Name[MAX_SIZE] = {0};
int endLoop = 0;
//Process
GetInput (Name, E_Data);
while (endLoop == 0){
selection = GetSelection ();
switch (selection) {
//update employee
case 1:
enterHours(E_Data);
break;
//enter employee hours
case 2:
editEmployee (E_Data);
break;
//edit employee information
case 3:
//newEmployee (E_Data);
break;
//add new employee
case 4:
ReportFile(E_Data);
//Summary
break;
case 5:
endLoop = TRUE;
break;
//Exit the program
} //end switch
SaveData ( Name, E_Data);
}//End while
} // end function main
///////////////////////////////////////////////////////////////////////////////
// Function Name : GetSelection
//
// Originated : April 20, 2009
//
// Abstract : Promps the user for the selection the user wants to do.
//
// Parameters : none
//
// Return Value : The selection the user wants to do to the data
//
// Misc. I/O : na
//
// Revisions : none
///////////////////////////////////////////////////////////////////////////////
int GetSelection (void) {
// Local Variables
int endLoop = 0;
int iValue = 0;
// Begin
while( endLoop == 0) {
printf(" Welcome to ESLR, LLC \n"
"1-Enter Employee Hours \n"
"2-Edit Employee Information \n"
"3-Add New Employee \n"
"4-Creat A Report \n"
"5-Exit Program \n"); /*Prompt for input*/
scanf( "%d", &iValue);
if ((iValue > 5) || (iValue < 1)){
system("cls");
printf("Invalid entry, please try again.\n\n");
} //end if statement
else {
endLoop = 1;
} //end else statement
} //end while statement);
return iValue;
} // end GetSelection function
///////////////////////////////////////////////////////////////////////////////
// Function Name : GetInput
//
// Originated : April 20, 2009
//
// Abstract :
//
// Parameters : The List array.
//
// Return Value : none
//
// Misc. I/O : na
//
// Revisions : none
///////////////////////////////////////////////////////////////////////////////
void GetInput (char userName[], double E_Data[]) {
//Array Slot 0 = employee social security number //
//Array Slot 1 = employee elected withholding //
//Array Slot 2 = employee hourly wage //
//Array Slot 3 = employee weekly hours //
//Array Slot 4 = gross wages for week //
//Array Slot 5 = federal tax for week //
//Array Slot 6 = social security tax for week //
//Array Slot 7 = medicare tax for week //
//Array Slot 8 = state tax for week //
//Array Slot 9 = county tax for week //
//Array Slot 10 = net pay for week //
//Array Slot 11 = ytd gross wages //
//Array Slot 12 = ytd federal withholding tax //
//Array Slot 13 = ytd social security tax //
//Array Slot 14 = ytd medicare tax //
//Array Slot 15 = ytd state tax //
//Array Slot 16 = ytd county tax //
//Array Slot 17 = ytd netpay //
// Local Variables
int continueWhileLoop = TRUE;
int nameLenght = 0;
double endofFile = FALSE;
double FileValue = FALSE;
FILE *fileHandle = NULL;
int i = 0;
// Begin
//Get File
while (continueWhileLoop == TRUE){
printf("Please enter in your Name:\n");
gets(userName);
system("cls"); //clear the screen
while (userName[nameLenght] != 0){
nameLenght++;
}
for(i = nameLenght; i > 0; i=i-1);{
printf("username = %s\ni = %d\n\n\n\n",userName,nameLenght);
userName[i + 3] = userName[i];
} // end For loop
printf("%s\n\n",userName);
userName[0] = 'c';
userName[1] = ':';
userName[2] = '\\';
printf("%s\n",userName);
userName[nameLenght + 3]='.';
printf("%s\n",userName);
userName[nameLenght + 4]='t';
printf("%s\n",userName);
userName[nameLenght + 5]='x';
printf("%s\n",userName);
userName[nameLenght + 6]='t';
printf("%s\n",userName);
fileHandle = fopen(userName,"r");
printf("%s",userName);
if (fileHandle == NULL){
printf("\nName not found! Please try again. \n");
} //end if
else {
continueWhileLoop = FALSE;
} //end else
}// end while function
while (endofFile != EOF){
for (i = 0; i < 18; i++){
E_Data[i] = FileValue;
endofFile = fscanf(fileHandle,"%lf",&FileValue);
} // end for loop
} // end while function
fclose(fileHandle);
} // end GetInput function
///////////////////////////////////////////////////////////////////////////////
// Function Name : SaveData
//
// Originated : April 20, 2009
//
// Abstract :
//
// Parameters : The List array.
//
// Return Value : none
//
// Misc. I/O : na
//
// Revisions : none
///////////////////////////////////////////////////////////////////////////////
void SaveData (char Name[], double E_Data[]) {
// Local Variables
double endofFile = FALSE;
double FileValue = FALSE;
FILE *fileHandle = NULL;
int i = 0;
// Begin
//Get File
fileHandle = fopen(Name,"w");
if (fileHandle == NULL){
printf("\nSaving Error!\n");
} //end if
else{
for (i = 0; i < 18; i++){
fprintf(fileHandle,"%f",E_Data[i]);
} // end for loop
} // end else statment
fclose(fileHandle);
} // end SaveData
///////////////////////////////////////////////////////////////////////////////
// Function Name : ReportFile
//
// Originated : April 20, 2009
//
// Abstract :
//
// Parameters : none
//
// Return Value : The selection the user wants to do to the data
//
// Misc. I/O : na
//
// Revisions : none
///////////////////////////////////////////////////////////////////////////////
void ReportFile (double E_Data[]) {
// Local Variables
// Begin
system("cls");
printf("Employee social security number: %0.0f\n",E_Data[0]);
printf("Employee elected withholding: $%0.2f\n",E_Data[1]);
printf("Employee hourly wage: $%0.2f\n",E_Data[2]);
printf("Employee weekly hours: $%0.2f\n",E_Data[3]);
printf("Gross wages for week: $%0.2f\n",E_Data[4]);
printf("Federal tax for week: $%0.2f\n",E_Data[5]);
printf("Social security tax: $%0.2f\n",E_Data[6]);
printf("Medicare tax for week: $%0.2f\n",E_Data[7]);
printf("State tax for week: $%0.2f\n",E_Data[8]);
printf("County tax for week: $%0.2f\n",E_Data[9]);
printf("Net pay for week: $%0.2f\n",E_Data[10]);
printf("ytd gross wages: $%0.2f\n",E_Data[11]);
printf("ytd federal withholding tax: $%0.2f\n",E_Data[12]);
printf("ytd social security tax: $%0.2f\n",E_Data[13]);
printf("ytd medicare tax: $%0.2f\n",E_Data[14]);
printf("ytd state tax: $%0.2f\n",E_Data[15]);
printf("ytd county tax: $%0.2f\n",E_Data[16]);
printf("ytd netpay: $%0.2f\n\n",E_Data[17]);
system("pause");
system("cls");
} // end ReportFile
//end of FinalProject.c
///////////////////////////////////////////////////////////////////////////////
// Function Name : EditEmployee Information
//
// Originated : April 20, 2009
//
// Abstract :
//
// Parameters : none
//
// Return Value : The selection the user wants to do to the data
//
// Misc. I/O : na
//
// Revisions : none
///////////////////////////////////////////////////////////////////////////////
void editEmployee (double E_Data[]) {
// Local Variables
// Begin
system("cls");
printf("Please edit the following information of the Employee \n");
printf("Employee social security number: \n");
scanf("%lf", &E_Data[0]);
printf("Employee elected withholding: \n");
scanf("%lf", &E_Data[1]);
printf("Employee hourly wage: \n");
scanf("%lf", &E_Data[2]);
//end gathering information
//clear system and restate to the prompt function
system("cls");
} //end editEmployee function
///////////////////////////////////////////////////////////////////////////////
// Function Name : newEmployee
//
// Originated : April 20, 2009
//
// Abstract :
//
// Parameters : none
//
// Return Value : The selection the user wants to do to the data
//
// Misc. I/O : na
//
// Revisions : none
///////////////////////////////////////////////////////////////////////////////
void newEmployee (double E_Data[]) {
// Local Variables
// Begin
system("cls");
printf("Please Enter The Following Information For A New Employee /n");
printf("Please enter their full name: /n");
scanf("%1f", &E_Data);
printf("Employee social security number:\n");
scanf("%lf", &E_Data[0]);
printf("Employee elected withholding:\n");
scanf("%lf", &E_Data[1]);
printf("Employee hourly wage:/n");
scanf("%lf", &E_Data[2]);
//end gathering information
//clear system and restate to the prompt function
system("cls");
} //end editEmployee function
///////////////////////////////////////////////////////////////////////////////
// Function Name : enterHours
//
// Originated : April 20, 2009
//
// Abstract :
//
// Parameters : none
//
// Return Value : The selection the user wants to do to the data
//
// Misc. I/O : na
//
// Revisions : none
///////////////////////////////////////////////////////////////////////////////
void enterHours (double E_Data[]) {
// Local Variables
// Begin
system("cls");
printf("Employee elected withholding: $%0.2f\n",E_Data[1]);
printf("Employee hourly wage: $%0.2f\n",E_Data[2]);
printf("Employee weekly hours: \n");
scanf("%lf", &E_Data[3]);
if (E_Data[3] <= 40){
E_Data[4] = E_Data[3] * E_Data[2];
} //end if
else {
int overtime;
overtime = ((E_Data[3] - 40) * ( E_Data[2] * 1.5));
E_Data[4] = overtime + (E_Data[3] * E_Data[2]);
} //end else
//printf("Gross wages for week: $%0.2f\n",E_Data[4]);
//printf("Federal tax for week: $%0.2f\n",E_Data[5]);
E_Data[5] = (E_Data[4] * .20);
//printf("Social security tax: $%0.2f\n",E_Data[6]);
E_Data[6] = (E_Data[4] * .20);
//printf("Medicare tax for week: $%0.2f\n",E_Data[7]);
E_Data[7] = (E_Data[4] * .20);
//printf("State tax for week: $%0.2f\n",E_Data[8]);
E_Data[8] = (E_Data[4] * .20);
//printf("County tax for week: $%0.2f\n",E_Data[9]);
E_Data[9] = (E_Data[4] * .20);
//printf("Net pay for week: $%0.2f\n",E_Data[10]);
E_Data[10] = (E_Data[4] - (E_Data[5] + E_Data[6] + E_Data[7] + E_Data[8] + E_Data[9]));
//printf("ytd gross wages: $%0.2f\n",E_Data[11]);
//printf("ytd federal withholding tax: $%0.2f\n",E_Data[12]);
//printf("ytd social security tax: $%0.2f\n",E_Data[13]);
//printf("ytd medicare tax: $%0.2f\n",E_Data[14]);
//printf("ytd state tax: $%0.2f\n",E_Data[15]);
//printf("ytd county tax: $%0.2f\n",E_Data[16]);
//printf("ytd netpay: $%0.2f\n\n",E_Data[17]);
system ("cls");
} //ending program of entering hours