I've looked this up over and over and every post I come up with has something to do with Objective-C. Nobody has been able to tell me what it means. I am not writing Objective-C code, but I am using the Xcode compiler, which is designed specifically for Objective-C.
When I compile, there is no error, instead it hangs up during runtime when it hits certain lines.
I was hoping somebody could compile this on a windows machine and tell me what happens (as I don't own one).
If more information about the exact error is needed I can provide it, but it is a lot of writing so I won't clutter the initial post with it. (Xcode shows where in the assembly code the program goes bad, so if someone knows assembly I will provide that)
here is main.h:
Code:
#include <string.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#define HEADINGS "Employee Name Rate Hours Gross Tax Net\n"
//#define HEADINGS " Rate Hours Gross Tax Net\n"
#define FORMAT "%-24s %4.2f %9.2f %10.2f %7.2f %7.2f\n"
//#define FORMAT "%4.2f %9.2f %10.2f %7.2f %7.2f\n"
#define TAXRATE .15
int main(void); //3.0
void openFile(void); //3.1
void mainLoop(void); //3.2
char* getName(char* firstName, char* lastName); //3.2.1
char* getFirstName(void); //3.2.1.1
char* getLastName(void); //3.2.1.2
float getHours(void); //3.2.2
float getPayrate(void); //3.2.3
void printReport(void); //3.2.4
float calcGross(void); //3.2.4.1
float calcTax(void); //3.2.4.2
float calcNet(void); //3.2.4.3
void askToContinue(void); //3.2.5
void closeFile(void); //3.3
FILE* report;
char* fullName;
char* firstName;
char* lastName;
float hours;
float payrate;
float gross;
float tax;
float net;
char* answer;
int continueBool;
and here is main.c:
Code:
#include "main.h"
//3.0
int main(void) {
openFile();
mainLoop();
closeFile();
return 0;
}
//3.1
void openFile(void) {
report = fopen("/Users/mike/Desktop/report.txt", "w");
fprintf(report, HEADINGS);
printf(HEADINGS);
}
//3.2
void mainLoop(void) {
continueBool = 1;
while (continueBool == 1) {
getName(firstName, lastName);
getPayrate();
getHours();
calcGross();
calcTax();
calcNet();
printReport();
askToContinue();
}
}
//3.2.1
char* getName(char* firstName, char* lastName) {
sprintf(fullName, "%s, %s", lastName, firstName);
return fullName;
}
//3.2.1.1
char* getFirstName(void) {
printf("Enter first name: ");
scanf("%s", &firstName);
return firstName;
}
//3.2.1.2
char* getLastName(void) {
printf("Enter last name: ");
scanf("%s", &lastName);
return lastName;
}
//3.2.2
float getHours(void) {
printf("Enter hours worked: ");
scanf("%f", &hours);
return hours;
}
//3.2.3
float getPayrate(void) {
printf("Enter hourly pay rate: $");
scanf("%f", &payrate);
return payrate;
}
//3.2.4
void printReport(void) {
printf(FORMAT, fullName, payrate, hours, gross, tax, net);
//printf(FORMAT, payrate, hours, gross, tax, net);
fprintf(report, FORMAT, fullName, payrate, hours, gross, tax, net);
//fprintf(report, FORMAT, payrate, hours, gross, tax, net);
}
//3.2.4.1
float calcGross(void) {
if (hours <= 40) {
gross = hours * payrate;
return gross;
} else {
gross = (payrate * 40) + ((hours - 40) * (payrate * 1.5));
return gross;
}
}
//3.2.4.2
float calcTax(void) {
tax = gross * TAXRATE;
return tax;
}
//3.2.4.3
float calcNet(void) {
net = gross - tax;
return tax;
}
//3.2.5
void askToContinue(void) {
printf("Would you like to make another entry? [Y/N]");
scanf("%s", &answer);
if ((strcmp(answer, "Y") && strcmp(answer, "y")) != 0) {
continueBool = 0;
}
}
//3.3
void closeFile(void) {
fclose(report);
}
Thanks for your time.