View Full Version : payroll program is 99% complete just need u to help mi single out a error
zangetsu
01-28-2010, 12:44 AM
my function was working all fine and dandy but boring until my friend separated the function for me which we are suppose(required by teacher) to do and now my program stops after i enter the first and last name ( i was the one that added multiple return 0 i am running out of time this is due friday and i have to draw flow charts for these please help me
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main()
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname[50];
char lname[20];
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[50]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[20]);
return 1;
}
int add_hours()
{
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
int hours;
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 2;
}
int salary_select()
{
int education_tax;
int NIS_tax;
int NHT_tax;
int medical_dental;
int hours;
int salary_deduct=0;salary_deduct>20;salary_deduct++;
int normal_pay;
int over_time; /*Overtime pay increases the pay rate from $20 to $25*/
int bonus=0;bonus>1;bonus++; /* Adds $3000 to workers going over 70 hours*/
normal_pay=hours*20;
over_time=(hours-60)*40+normal_pay;
bonus=over_time+3000;
salary_deduct=hours*20-hours*10;
if(hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is%d dollars\n",salary_deduct);
else if(hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is%d dollars\n",normal_pay);
else if(hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is%d dollars\n",over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is%d\n",bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 3;
}
int tax()
{
int normal_pay;
int over_time; /*Overtime pay increases the pay rate from $20 to $25*/
int bonus=0;bonus>1;bonus++; /* Adds $3000 to workers going over 70 hours*/
int salary_deduct=0;salary_deduct>20;salary_deduct++;
int hours;
int education_tax;
int NIS_tax;
int NHT_tax;
int medical_dental;
education_tax=hours*20*.06;
NHT_tax=hours*20*.1;
medical_dental=hours*20*.05;
NIS_tax=hours*20*.05;
printf("Education tax of %6-%d\n",education_tax);
printf("NHT tax of %10-%d\n",NHT_tax);
printf("NIS tax of %5-%d\n",NIS_tax);
printf("Medical/dental of %5-%d\n",medical_dental);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 4;
}
int ntpay()
{
int normal_pay;
int over_time; /*Overtime pay increases the pay rate from $20 to $25*/
int bonus=0;bonus>1;bonus++; /* Adds $3000 to workers going over 70 hours*/
int education_tax;
int NIS_tax;
int NHT_tax;
int medical_dental;
int salary_deduct=0;salary_deduct>20;salary_deduct++;
int hours;
int netpay;
int netpay1;
int netpay2;
int netpay3;
netpay=salary_deduct-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay1=normal_pay-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay2=over_time-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay3=bonus-(NHT_tax+education_tax+NIS_tax+medical_dental);
if(hours<=40)
printf("The net pay is%d\n",netpay);
else if(hours<=60)
printf("The net pay is%d\n",netpay1);
else if(hours<=70)
printf("The net pay is%d\n",netpay2);
else
printf("The net pay is%d\n",netpay3);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 5;
}
Fou-Lu
01-28-2010, 05:06 AM
You're going to need to edit this to wrap it completely in code tags instead of these partial blocks.
You're main returns 1 (generally a failure code) immediately after a scanf. So you're not doing anything with you're input. You'll need to correct you're input as well, as it is you're placing input into the final memory locations instead of the first: &arr[0] is what you want.
zangetsu
01-28-2010, 03:30 PM
k i have no idea what yur saying but hears the new thing i am going to post the old version when it was orking and then ask if anyone can pls help mi or show mi to a post where i can learn how to separate the different functions
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main()
{
int hours;
int mo, tu, we, th, fr;
int salary_deduct=0;salary_deduct>20;salary_deduct++;
int normal_pay;
int over_time; /*Overtime pay increases the pay rate from $20 to $25*/
char fname[50];
char lname[20];
int bonus=0;bonus>1;bonus++; /* Adds $3000 to workers going over 70 hours*/
int taxdeduct;
int education_tax;
int NIS_tax;
int NHT_tax;
int medical_dental;
int netpay;
int netpay1;
int netpay2;
int netpay3;
{
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[50]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[20]);
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
}
{
hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",hours);
salary_deduct=hours*20-hours*10;
normal_pay=hours*20;
over_time=(hours-60)*40+normal_pay;
bonus=over_time+3000;
}
if(hours<=40)
printf("\nThe employee %s is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",fname,salary_deduct);
else if(hours<=60)
printf("\nThe employee %s will get normal pay\n The gross pay is:$%d dollars\n",fname,normal_pay);
else if(hours<=70)
printf("\nThe employee %s is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",fname,over_time);
else
printf("\nTHE EMPLOYEE %s IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",fname,bonus);
education_tax=hours*20*.06;
printf("Education tax:$-%d\n",education_tax);
NHT_tax=hours*20*.1;
printf("NHT tax:$-%d\n",NHT_tax);
NIS_tax=hours*20*.05;
printf("NIS tax:$-%d\n",NIS_tax);
medical_dental=hours*20*.05;
printf("Medical/dental:$-%d\n",medical_dental);
netpay=salary_deduct-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay1=normal_pay-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay2=over_time-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay3=bonus-(NHT_tax+education_tax+NIS_tax+medical_dental);
if(hours<=40)
printf("The net pay is:$%d\n",netpay);
else if(hours<=60)
printf("The net pay is:$%d\n",netpay1);
else if(hours<=70)
printf("The net pay is:$%d\n",netpay2);
else
printf("The net pay is:$%d\n",netpay3);
return 0;
}
Fou-Lu
01-28-2010, 04:19 PM
Ok, what I'm saying is that you need to actually call these functions. Right now they are not doing anything.
First and foremost, you'll need to read up on what's called scope. Even after calling these methods, you cannot capture these variables since they are all stored in dynamic memory, so they are destroyed when the function stack is terminated. You'll need to either return a value or manipulate a single variable via pointer reference:
int main(int argc, char **argv)
{
int hours = 0;
add_hours(&hours);
}
void add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
Or you need to return the value and shove it into a variable in you're main.
Since this is a homework assignment, there is little more I can provide for code wise, you'll need to ask more specific questions.
Also, look into the purpose of you're return values. I can't help but notice that each of you're functions are returning an incrementing value for its result, so I'm thinking you need to learn what the return's purpose is.
zangetsu
01-29-2010, 01:02 PM
the int mai part right there is it global or local and what does the **char thing do how do i make functions like salary selection global
Fou-Lu
01-29-2010, 02:20 PM
the int mai part right there is it global or local and what does the **char thing do how do i make functions like salary selection global
These are all local scope variables. Global are declared outside of functions, as soon as one is declared inside a function it will take a local scope to that function. The signature int main(int argc, char **argv) makes the variables argc and argv local to the main function. These are the parameter list that it is pass when invoked. You needn't worry about where these come from for the main function itself, it is a gateway thats automatically called when executed (if available, which in a .exe is required).
A char ** is a pointer to a char pointer, which is essentially an array of strings. If you're unfamiliar with pointers, this is something you'll learn later, since it is a rather complicated process. To change the third letter in the second "string", it would look something like this: *(*(argv + 1) + 2) = 'A';. This has no verification on it of course, I was too lazy to write that all in o.O. You have actually been doing this with the scanf function - it requires pointers to change the value, so using &myint is giving it a pointer to variable myint. This is why I was mentioning that this: scanf("%s",&fname[50]); is a problem, it will grab the address of the 50'th char's value and start writing from there. This should be fname[0] or even just fname should work. Arrays are sort of like pointers and are treated as such.
Main should have two arguments: int, char **, to indicate the number of launch arguments provided and what they are. The definition you may see differently, things like: char *argv[] for example. It will always have at least 1 parameter (the executable itself).
These functions are all global. In more strict compiling, the complete code would fail to compile since the main method cannot find them prior to the call. This is a once-pass compiler. Two-pass will issue a warning. The way to make you're functions unavailable is by using the static keyword, but it will still be available to all functions within that current .c file.
zangetsu
01-29-2010, 05:42 PM
DUDE I NEED MAJOR HELP THE DEADLINE IS TODAY AND THIS IS MY FITURE BRO THIS WHAT I DID SO FAR BUT I NEED THE OTHE TWO TO ADD TO THIS ONE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname[50];
char lname[20];
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[50]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[20]);
int hours=0;
add_hours(&hours);
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
i need to add these to the first part cause the upper two are working but i need these functions to add to it help mi pls this should go in today bro
int salary_select()
{
int education_tax;
int NIS_tax;
int NHT_tax;
int medical_dental;
int hours;
int salary_deduct=0;salary_deduct>20;salary_deduct++;
int normal_pay;
int over_time; /*Overtime pay increases the pay rate from $20 to $25*/
int bonus=0;bonus>1;bonus++; /* Adds $3000 to workers going over 70 hours*/
normal_pay=hours*20;
over_time=(hours-60)*40+normal_pay;
bonus=over_time+3000;
salary_deduct=hours*20-hours*10;
if(hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",salary_deduct);
else if(hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",normal_pay);
else if(hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
int tax()
{
int normal_pay;
int over_time; /*Overtime pay increases the pay rate from $20 to $25*/
int bonus=0;bonus>1;bonus++; /* Adds $3000 to workers going over 70 hours*/
int salary_deduct=0;salary_deduct>20;salary_deduct++;
int hours;
int education_tax;
int NIS_tax;
int NHT_tax;
int medical_dental;
float num1;
float num2;
printf("Enter the percentage that should be calculated on this tax:%f \n",&num1);
num2=num1/100;
education_tax=hours*20*num2;
NHT_tax=hours*20*num2;
medical_dental=hours*20*num2;
NIS_tax=hours*20*num2;
printf("Education tax of %6:$-%d\n",education_tax);
printf("NHT tax of %10:$-%d\n",NHT_tax);
printf("NIS tax of %5:$-%d\n",NIS_tax);
printf("Medical/dental of %5:$-%d\n",medical_dental);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
int ntpay()
{
int normal_pay;
int over_time; /*Overtime pay increases the pay rate from $20 to $25*/
int bonus=0;bonus>1;bonus++; /* Adds $3000 to workers going over 70 hours*/
int education_tax;
int NIS_tax;
int NHT_tax;
int medical_dental;
int salary_deduct=0;salary_deduct>20;salary_deduct++;
int hours;
int netpay;
int netpay1;
int netpay2;
int netpay3;
netpay=salary_deduct-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay1=normal_pay-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay2=over_time-(NHT_tax+education_tax+NIS_tax+medical_dental);
netpay3=bonus-(NHT_tax+education_tax+NIS_tax+medical_dental);
if(hours<=40)
printf("The net pay is:$%d\n",netpay);
else if(hours<=60)
printf("The net pay is:$%d\n",netpay1);
else if(hours<=70)
printf("The net pay is:$%d\n",netpay2);
else
printf("The net pay is:$%d\n",netpay3);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
Fou-Lu
01-30-2010, 02:28 PM
Well I hope you're project was finished alright.
Like I said, you needed to still call you're functions, and learn how the scope was going to affect the variables you were trying to manipulate. From there, you needed to learn whether to return a result and store it or manipulate a variable by reference.
zangetsu
01-30-2010, 04:22 PM
Nope it wasn't finished actually no one in my entire class was finished so hopefully he doesn't flunk us all but thanks anyways for helping me this far i don't know if he will still collect it from us but i would still like to finish it with your help if thats ok cause he might probably collect it on monday? question u said to manipulate the variable to return it is this an example of that even though it C++
#include <iostream>
using namespace std;
int subtraction (int a, int b)
{
int r;
r=a-b;
return (r);
}
int main ()
{
int x=5, y=3, z;
z = subtraction (7,2);
cout << "The first result is " << z << '\n';
cout << "The second result is " << subtraction (7,2) << '\n';
cout << "The third result is " << subtraction (x,y) << '\n';
z= 4 + subtraction (x,y);
cout << "The fourth result is " << z << '\n';
return 0;
}
and can u pls show mi an example of the second option and which one is easier to learn?
Fou-Lu
01-30-2010, 07:06 PM
Yes, its very similar in C. Function calling is identical infact, at least for this. C++ has n object base to it unlike C, and in all honesty I'm afraid I'm not that familiar with C++ (my OO programming is generally done in C#, Java and PHP).
int pow3(int i)
{
// I'm just going to use basic multiplication:
return i * i * i;
}
int main(int c, char **a)
{
int i = 5;
printf("%d\n", pow3(i));
// You can reassign as well:
i = pow3(i); // Now i is 125
}
The purpose of functions is for code reuse. If you're familiar with objects, its essentially the same as writing a class and using its methods to support its instance. Functions can be very complicated, but start easy. Generally in you're header file you declare what a function is expected to do by its signature. A signature returns a result (more on this soon), is given a unique name, and a parameter list:
int pow3(int);
That simply says I have a function that I can use, called pow3, that will take one integer and return an integer. In header files, this is just the signature, you need not provide it with any body nor the actual parameter names, just their datatypes. From an OO perspective, this is the same as interfacing except that there is still no guarantee that this function exists in C (its up to us to make sure its available, the compiler should choke if its unavailable when trying to call it).
Now, as for referencing versus non-referencing parameter lists. In C, functions can take either a datatype or whats called a pointer to * where * is the datatype. Pointers are the actual memory address where the variable is stored, instead of just a copy of the value. This lets you alter the original value of the provided variable, so you may not need to return a result. Lets go with the pow3 example for both:
int pow3(int i) // signature: name pow3 returns int, requires int
{
return i * i * i; // Return the result of i^3
}
void cubed(int *i) // signature: name cubed [ie: pow3], returns nothing (void), requires pointer to integer
{
// This is where it is different, we do not return, yet we can alter the original:
*i = *i * *i * *i; // Yes, it looks odd.
}
// Called in main as:
int i = 2;
int i2 = 2;
i = pow3(i); // i is now 8
cubed(&i2); // Notice no assignment, but i2 is now also 8.
Notice that cubed expects a pointer (the memory address for the variable), so we use the addressof operator (&). Because of this, referenced variables cannot be constants (ie: we cannot use cubed(5), but we can use pow3(5) and store the result).
Pointer dereferencing takes the syntax of *variable. So, when provided a memory address, we retrieve what it actually has stored at that location with *variable. Thats why the code *i = *i * *i * *i; looks so odd. We need to get the value of i (*i) and multiply it 3 times (ignoring using the built in math functions), and store the result into the value of i (also *i).
Pointers can have a pretty much infinite depth to them (the most I've ever needed is 3 levels). Complication crops up rather fast on handling. C has no String datatype, so its actually an array of chars. C treats arrays much the same as pointers (arrays you can actually drag the size off of, pointers are always the size of the bus, so 32 bits or 64 bits for example). An array of 'strings' in C is therefore a char pointer pointer, or char **.
Now this is starting to get quite complicated, so I'd recommend actually trying to ignore this stuff until it pertains to you, but you can also have function pointers, which is essentially a callback, delegate, or whatever you want to call it if you're familiar with C#, php, java etc. What it allows you to do is use an unspecified function. A great example is a sort method, where the comparator can be whatever you want it to be:
// err, off the cuff here, not 100% certain this will work >.<
int (*sortComparator)(void *, void *) = NULL;
// Now, you can do a sort with an unknown function. We will not get into sorting algorithms though:
void mySorter(void *list, int (*sortComparator)(void *v1, void *v2))
{
// Run sort algorithm, when comparing just call sortComparator to determine the comparison
}
// Define a quick comparator:
int intComparator(int *i, int *i2)
{
return *i2 - *i;
}
// Call with:
sortComparator = &intComparator;
// Have a list of some sorts:
mySorter(&list, sortComparator);
Does that all make sense?
Don't let anyone fool you, C is one of the more complicated languages out there. Oracleguy may pop in here to let me know if I'm wrong on anything here - he is much much better with C than I am, but I'm trying hard to learn as much as I can (I do C tutoring for the students @ college here).
zangetsu
01-30-2010, 11:56 PM
i think i'm kinda getting the hang of it i am reading your older posts and you said that one option for me was to shove the variables into main right? So basically my program jus needs some referencing after the separation? SO should i set up referencing above main(meaning globally) and also right below main.
This is the code u wrote for me i tried it but i had to replace void with int for it to work, anyways in order for me to get a better understanding of referencing can u show some comments on this program as to what does what and why just some little cave man comments for me lol please and thanks after this i think i should be ready to deal with mine and thanks in advance for taking the time out to help me i really really super really appreciate it.
int main(int argc, char **argv)
{
int hours = 0;
add_hours(&hours);
}
void add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
zangetsu
01-31-2010, 12:22 AM
I tried it but it keeps ignoring the if statements
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname[50];
char lname[20];
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[50]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[20]);
int hours=0;
add_hours(&hours);
int bonus=40;
salaryselect(&bonus);
int salary_deduct=80;
salaryselect(&salary_deduct);
int normal_pay=60;
salaryselect(&normal_pay);
int over_time=70;
salaryselect(&over_time);
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int argc, int hours)
{
int salary_deduct=0;salary_deduct>1;salary_deduct++;
int normal_pay;
int over_time; /*Overtime pay increases the pay rate from $20 to $25*/
int bonus=0;bonus>1;bonus++; /* Adds $3000 to workers going over 70 hours*/
normal_pay=hours*20;
over_time=(hours-60)*40+normal_pay;
bonus=over_time+3000;
salary_deduct=hours*20-hours*10;
if(hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",salary_deduct);
else if(hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",normal_pay);
else if(hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
zangetsu
01-31-2010, 02:56 PM
I am tried again to single out a little error but cant get rid of it
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int argc, int salary_deduct=0, int normal_pay=0, int over_time=0, int bonus=0)
{
int hours=0;
int salary_deduct=0;
int normal_pay=0;
int over_time=0; /*Overtime pay increases the pay rate from $20 to $25*/
int bonus=0; /* Adds $3000 to workers going over 70 hours*/
normal_pay=hours*20;
over_time=(hours-60)*40+normal_pay;
bonus=over_time+3000;
salary_deduct=hours*20-hours*10;
if(hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",salary_deduct);
else if(hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",normal_pay);
else if(hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname[50];
char lname[20];
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[50]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[20]);
int hours=0;
add_hours(&hours);
int bonus=0;
salaryselect(&bonus);
int salary_deduct=0;
salaryselect(&salary_deduct);
int normal_pay=0;
salaryselect(&normal_pay);
int over_time=0;
salaryselect(&over_time);
}
oracleguy
01-31-2010, 06:18 PM
I am tried again to single out a little error but cant get rid of it
What is the error? Help us help you by giving specific details. Despite Fou-Lu's programming prowess, I don't think he has achieved telepathy.
zangetsu
01-31-2010, 06:34 PM
u would have to prob run it in code blocks or something to see it but it says something about line 34 i think it is. says something about error before the = sign and this is due tomorrow and i have another function to attach unto this whole thing
int salaryselect(int argc, int salary_deduct=0, int normal_pay=0, int over_time=0, int bonus=0)
zangetsu
02-01-2010, 01:06 AM
my code keeps giving the windows error report when it reaches a certain part run it n chek it out pls
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname[50];
char lname[20];
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[0]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[0]);
int hours=0;
add_hours(&hours);
int bonus;
salaryselect(&bonus);
int salary_deduct;
salaryselect(&salary_deduct);
int normal_pay;
salaryselect(&normal_pay);
int over_time;
salaryselect(&over_time);
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*bonus=*over_time+3000;
*salary_deduct=*hours*20-*hours*10;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
oracleguy
02-01-2010, 01:40 AM
u would have to prob run it in code blocks or something to see it but it says something about line 34 i think it is. says something about error before the = sign and this is due tomorrow and i have another function to attach unto this whole thing
int salaryselect(int argc, int salary_deduct=0, int normal_pay=0, int over_time=0, int bonus=0)
If this is a C program, which it looks like, you cannot provide default values for parameters. That is a C++ thing.
zangetsu
02-01-2010, 01:44 AM
check this one out
my code keeps giving the windows error report when it reaches a certain part run it n chek it out pls
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname[50];
char lname[20];
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[0]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[0]);
int hours=0;
add_hours(&hours);
int bonus;
salaryselect(&bonus);
int salary_deduct;
salaryselect(&salary_deduct);
int normal_pay;
salaryselect(&normal_pay);
int over_time;
salaryselect(&over_time);
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*bonus=*over_time+3000;
*salary_deduct=*hours*20-*hours*10;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
oracleguy
02-01-2010, 01:55 AM
my code keeps giving the windows error report when it reaches a certain part run it n chek it out pls
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname[50];
char lname[20];
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[0]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[0]);
int hours=0;
add_hours(&hours);
int bonus;
salaryselect(&bonus);
int salary_deduct;
salaryselect(&salary_deduct);
int normal_pay;
salaryselect(&normal_pay);
int over_time;
salaryselect(&over_time);
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*bonus=*over_time+3000;
*salary_deduct=*hours*20-*hours*10;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
This is C, declare all your variables in a function before any other code.
You don't return anything from the function add_hours. Either make the return type void or return something.
You don't return anything from main.
You need to provide function prototypes for add_hours and salaryselect before main.
You call salary select 4 times but with only one parameter each time, the function takes 5 parameters, I suspect this is the core issue of your problem with the program
You'll see once salaryselect is properly declared, the program will not compile because it doesn't have enough arguments. Pass the correct number of variables into the function and your program will work. I fixed issues 1, 3 and 4 for you. Try and fix the other issues on your own since this homework after all.
I also cleaned up your formatting, properly formatting your code can help keep things easy to understand.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int add_hours(int *hours);
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus);
int main(int argc,char **argv)
{
char fname[50];
char lname[20];
int hours=0;
int bonus;
int salary_deduct;
int normal_pay;
int over_time;
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[0]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[0]);
add_hours(&hours);
salaryselect(&bonus);
salaryselect(&salary_deduct);
salaryselect(&normal_pay);
salaryselect(&over_time);
return 0;
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*bonus=*over_time+3000;
*salary_deduct=*hours*20-*hours*10;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
zangetsu
02-01-2010, 03:00 AM
it keeps saying too few arguments to salary select what does that even mean too few is the compiler serious and this is not some silly homework this is life changing assignment thats worth %20 on my final test i need to give this in bro pls help Dude this is not the time to go all Mr.MIagi on me i am not the karate kid if there was ever a time to mr.miagi it is not today bro trust mi this is life changing stuff man
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int add_hours(int *hours);
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus);
int main(int argc,char **argv)
{
char fname[50];
char lname[20];
int hours=0;
int bonus;
int salary_deduct;
int normal_pay;
int over_time;
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
printf("Enter the employee's First Name:\n");
scanf("%s",&fname[0]);
printf("Enter the employee's Last Name:\n");
scanf("%s",&lname[0]);
add_hours(&hours);
salaryselect(&bonus);
salaryselect(&salary_deduct);
salaryselect(&normal_pay);
salaryselect(&over_time);
return 0;
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*bonus=*over_time+3000;
*salary_deduct=*hours*20-*hours*10;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
zangetsu
02-01-2010, 03:05 AM
and could u be clrearer with the parameter thing and thanks for hwlping mi fix some of the errors my bad manners that was the first thing i should have said im sorry im just really stressed out now
Fou-Lu
02-01-2010, 03:01 PM
The signature of the function (defined by the return type, unique name and arguments, C doesn't allow overloading [to the best of my knowledge >.<]), doesn't match you're call:
// This says 5 parameters
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus);
// Called in main with:
// Each called with 1 argument (arguments mapped to parameters)
salaryselect(&salary_deduct);
salaryselect(&normal_pay);
salaryselect(&over_time);
This is the right idea, but you need to actually combine these variables into one call:
salaryselect(&hours, &salary_deduct, &normal_pay, &over_time, &bonus);
like that. So each call to you're function needs to have the same number of arguments provided as is expected by the signature.
So if you're signature is: void doStuffs(int a, const char *c);, you must call it with something like: doStuffs(12, "hello world");. Any missing or extra (not 100% certain about this one...) variables will kill you're compilation. There are ways to do variable length parameter lists in C, but I've never needed to actually use it.
Now, since these are taking pointers to you're variables, you don't really need to signature a return result for you're functions. One thing you may want to double check is that you're instructor is happy with you using pointers (mine were quite anal about it when it came to using pointers before it was covered in class). If they do not want you to use the pointers, then you simply provide ints for each parameter in the function, and return whatever you need outside of it.
zangetsu
02-02-2010, 12:47 AM
thx i think i'm finished but it keeps crashing at the en could u look at this or run this for me pls maybe its my compiler idk
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int add_hours(int *hours);
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus);
int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours);
int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3);
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname;
char lname;
printf("Enter the employee's First Name:\n");
scanf("%49s",&fname);
printf("Enter the employee's Last Name:\n");
scanf("%49s",&lname);
int hours=0;
int over_time=0;
int normal_pay=0;
int bonus=0;
int salary_deduct=0;
int education_tax=0;
int NHT_tax=0;
int NIS_tax=0;
int medical_dental=0;
int netpay=0;
int netpay1=0;
int netpay2=0;
int netpay3=0;
add_hours(&hours);
salaryselect(&hours,&salary_deduct,&normal_pay,&over_time,&bonus);
tax(&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&hours);
net_pay(&hours,&over_time,&normal_pay,&bonus,&salary_deduct,&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&netpay,&netpay1,&netpay2,&netpay3);
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*salary_deduct=*hours*20-*hours*10;
*bonus=*over_time+3000;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours)
{
*education_tax=*hours*20*.06;
printf("Education tax of %6:$-%d\n",*education_tax);
*NHT_tax=*hours*20*.1;
printf("NHT tax of %10:$-%d\n",*NHT_tax);
*NIS_tax=*hours*20*.05;
printf("NIS tax of %5:$-%d\n",*NIS_tax);
*medical_dental=*hours*20*.05;
printf("Medical/dental of %5:$-%d\n",*medical_dental);
}
int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3)
{
*netpay=*salary_deduct-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay1=*normal_pay-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay2=*over_time-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay3=*bonus-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
if(*hours<=40)
printf("The net pay is:$%d\n",*netpay);
else if(*hours<=60)
printf("The net pay is:$%d\n",*netpay1);
else if(*hours<=70)
printf("The net pay is:$%d\n",*netpay2);
else
printf("The net pay is:$%d\n",*netpay3);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
oracleguy
02-02-2010, 02:00 AM
While you get bonus points for the Karate Kid reference, you failed to do what you've already been told.
You need to put variable declarations before any function calls.
If the return type of a function is not void, such as int, you must return something
After I did that your program compiled and ran fine:
//*****************St.Jago High School******************\
------------Courtney Athlone St.Michael Reid---------------
^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^
Enter the employee's First Name:
foo
Enter the employee's Last Name:
bar
Enter daily hours for Monday:
40
Enter daily hours for Tuesday:
40
Enter daily hours for Wednesday:
38
Enter daily hours for Thursday:
38
Enter daily hours for Friday:
3
The weekly hours are:159
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
THE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!
The gross pay is:$10140
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Education tax of :$-190
NHT tax of :$-318
NIS tax of :$-159
Medical/dental of :$-159
The net pay is:$9314
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And as for your compiler, while compiler bugs due happen, they are extremely rare. More likely the an error is the fault is the programmer and not the compiler.
zangetsu
02-03-2010, 04:01 AM
it keeps crashing this is getting seriously annoying
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void add_hours(int *hours);
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus);
int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours);
int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3);
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname;
char lname;
printf("Enter the employee's First Name:\n");
scanf("%49s",&fname);
printf("Enter the employee's Last Name:\n");
scanf("%49s",&lname);
int hours=0;
int over_time=0;
int normal_pay=0;
int bonus=0;
int salary_deduct=0;
int education_tax=0;
int NHT_tax=0;
int NIS_tax=0;
int medical_dental=0;
int netpay=0;
int netpay1=0;
int netpay2=0;
int netpay3=0;
add_hours(&hours);
salaryselect(&hours,&salary_deduct,&normal_pay,&over_time,&bonus);
tax(&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&hours);
net_pay(&hours,&over_time,&normal_pay,&bonus,&salary_deduct,&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&netpay,&netpay1,&netpay2,&netpay3);
return 0;
}
void add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return int;
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*salary_deduct=*hours*20-*hours*10;
*bonus=*over_time+3000;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours)
{
*education_tax=*hours*20*.06;
printf("Education tax of %6:$-%d\n",*education_tax);
*NHT_tax=*hours*20*.1;
printf("NHT tax of %10:$-%d\n",*NHT_tax);
*NIS_tax=*hours*20*.05;
printf("NIS tax of %5:$-%d\n",*NIS_tax);
*medical_dental=*hours*20*.05;
printf("Medical/dental of %5:$-%d\n",*medical_dental);
return 0;
}
int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3)
{
*netpay=*salary_deduct-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay1=*normal_pay-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay2=*over_time-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay3=*bonus-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
if(*hours<=40)
printf("The net pay is:$%d\n",*netpay);
else if(*hours<=60)
printf("The net pay is:$%d\n",*netpay1);
else if(*hours<=70)
printf("The net pay is:$%d\n",*netpay2);
else
printf("The net pay is:$%d\n",*netpay3);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
return 0;
}
oracleguy
02-03-2010, 04:43 AM
It works fine for me. By "crashing" you mean after you enter the information, the window goes away? Or do you mean that it doesn't actually compile? Because I've noticed you have still ignored what I said, that code won't compile in most C compilers. If you are going to ask for help, you need to provide more detail and actually do what we suggested. C isn't like HTML, you can't sorta get it right, there is a clear right and wrong with the syntax.
I do notice you have a coding error:
return int;
The function is void so it doesn't return anything, secondly int is a data type and can't be used like a value.
zangetsu
02-04-2010, 04:23 PM
I have just been thrown a curve ball now i find out that i have to put a loop in my program in order to get full marks how do i go about doing that this is so frustrating an the the final thing is due tomorrow. I would probably want it to ask for another employee pls help min quckly
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int add_hours(int *hours);
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus);
int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours);
int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3);
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
char fname[50];
char lname[50];
printf("Enter the employee's First Name:\n");
scanf(" %[^\n0-9]s ",fname);
printf("Enter the employee's Last Name:\n");
scanf(" %[^\n0-9]s ",lname);
getchar();
int hours=0;
int over_time=0;
int normal_pay=0;
int bonus=0;
int salary_deduct=0;
int education_tax=0;
int NHT_tax=0;
int NIS_tax=0;
int medical_dental=0;
int netpay=0;
int netpay1=0;
int netpay2=0;
int netpay3=0;
add_hours(&hours);
salaryselect(&hours,&salary_deduct,&normal_pay,&over_time,&bonus);
tax(&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&hours);
net_pay(&hours,&over_time,&normal_pay,&bonus,&salary_deduct,&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&netpay,&netpay1,&netpay2,&netpay3);
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*salary_deduct=*hours*20-*hours*10;
*bonus=*over_time+3000;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours)
{
*education_tax=*hours*20*.06;
printf("Education tax of %6:$-%d\n",*education_tax);
*NHT_tax=*hours*20*.1;
printf("NHT tax of %10:$-%d\n",*NHT_tax);
*NIS_tax=*hours*20*.05;
printf("NIS tax of %5:$-%d\n",*NIS_tax);
*medical_dental=*hours*20*.05;
printf("Medical/dental of %5:$-%d\n",*medical_dental);
}
int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3)
{
*netpay=*salary_deduct-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay1=*normal_pay-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay2=*over_time-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay3=*bonus-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
if(*hours<=40)
printf("The net pay is:$%d\n",*netpay);
else if(*hours<=60)
printf("The net pay is:$%d\n",*netpay1);
else if(*hours<=70)
printf("The net pay is:$%d\n",*netpay2);
else
printf("The net pay is:$%d\n",*netpay3);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
Fou-Lu
02-04-2010, 04:44 PM
Can it be any loop? The easiest thing to do is create a reprompt menu, so just in you're main method you essentially wrap it all up into a do/while loop.
Logically:
declare char cContinue = 'Y';
do
CallAllMethodhandling
prompt "Continue?" > cContinue
while cContinue == 'Y' || cContinue == 'y'
So programatically, you simply create a control variable to determine if they should continue processing. What you do at this point, is predeclare you're variables at the top of you're function, and using you're loop you initialize them. The difference:
int i; // i has been declared as an integer.
i = 0; // i has been initialized and set a value of 0.
this has to happen in the loop so it resets all the input data on each run. Be warned that you will lose history of the changes if this is the approach you follow (previous manipulations will be lost once the values have been reset).
You'll actually kill two birds with one stone. You can use two loops to cover the above: the outer to determine if they want to process again, and an inner to make sure they are entering only a 'Y' or 'N' char.
zangetsu
02-05-2010, 02:42 AM
i'm not really and im out of time but where should i put the code and what to declare from what not to declare what do u mean by allmethodhandling? now my teach says he wants us to burn the code unto a cd hopefully i can burn it at school if i dont finish it tonight
zangetsu
02-05-2010, 04:43 PM
dude that was c++ idk that stuff and i am extremely out of time im gonna go read and see if i can put in a simple loop or something then get back to you prob time might be up by that time.
zangetsu
02-09-2010, 07:26 PM
how do i go about making a error checking program for this section like i wanna make the hours of the day only acept less than 24 hours where do i go to learn than stuff or can you give me som caveman instructions please.
int add_hours(float *hours)
{
int mo, tu, we, th, fr;
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%f\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
Fou-Lu
02-09-2010, 08:54 PM
Validation is quite simple, you can actually use you're loops here to take care of them:
do
{
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
if (mo < 0 || mo > 24)
{
printf("Invalid entry, please try again.\n");
}
flush(stdin);
} while (mo < 0 || mo > 24);
something like that. I can't test it or anything, but works in my head :P
oracleguy
02-09-2010, 11:36 PM
And really it could be a function, pass in the day and the variable you want to manipulate and have the loop with the prompt in the function.
zangetsu
02-10-2010, 12:13 AM
Fou lu,oracleguy u need to stop spoiling me .....jk but seriously though its cause im working with a deadline here y im always hectic but as soon as the project is over i wanna learn some stuff from scratch cause my teacher aint teaching nothin so pls show me some learning sites for me pls where i can learn this stuff and error checking easily again thx much
Fou-Lu
02-10-2010, 02:31 AM
Hmm, I found this one, and it looks pretty good: http://www.iu.hio.no/~mark/CTutorial/CTutorial.html
Note that there commonly using an old declaration style for their functions:
CalculateBill(starter,main,dessert) /* Adds up values */
int starter,main,dessert;
{ int total;
total = starter + main + dessert;
return (total);
}
The above is equivalent to the following style you're more used to:
int CalculateBill(int starter, int main, int dessert)
{
return starter + main + dessert;
}
So aside from being an old article, it looks pretty good.
zangetsu
02-10-2010, 02:52 AM
how do i declare flush and stdin is it in an #include thingy
oracleguy
02-10-2010, 02:54 AM
They should be brought in by stdio.h already.
zangetsu
02-10-2010, 03:11 AM
oops i tried fflush and it worked perfectly thx bro im gonna go check out the site you provided much thx again
zangetsu
02-10-2010, 02:36 PM
it keeps crashing as i enter a name
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <Windows.h>
#include <unistd.h>
int add_hours(int *hours);
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus);
int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours);
int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3);
int main(int argc,char **argv)
{
printf("\t//*****************St.Jago High School******************\\ \n\n");
printf("\t------------Courtney Athlone St.Michael Reid---------------\n\n");
printf("\t^^^^^^^^^Computer Science IA-Pay Roll System^^^^^^^^^\n\n");
printf("WARNING!!!!THIS PROGRAM IS ONLY FOR LOGICAL USERS AND NOT MONKEYS OR HUMANS WHO BANG OR DAMAGE KEYBOARDS\n AND YOU SHOULD NOT INPUT ANYTHING OUT OF THE ORDINARY UNLESS SPECIFIED.\nIF YOU ARE ASKED TO INPUT A NAME YOU SHOULD USE ONLY LETTERS OF THE ALPHABET\n, IF YOU ARE ASKED TO INPUT HOURS IT MEANS\n NUMBERS GREATER THAN OR EQUAL TO THE NUMERICAL DIGIT KNOWN AS ZERO WITHOUT USING ANY DECIMAL.\n\n\n\n");
char fname;
char lname;
do
{
printf("Enter the employee's First Name AND DO NOT INPUT ANY ANY NUMBERS OR FOOLISHNESS:\n");
scanf(" %[^\n0-9]s ",fname);
if (fname < 0 || fname > 0)
{
printf("Invalid entry, please try again.\n\a \a\a");
}
fflush(stdin);
} while (fname < 0 || fname > 0);
getchar();
do
{
printf("Enter the employee's Last Name AND DO NOT INPUT ANY ANY NUMBERS OR FOOLISHNESS:\n");
scanf(" %[^\n0-9]s ",lname);
if (fname < 0 || fname > 0)
{
printf("Invalid entry, please try again.\n\a \a\a");
}
fflush(stdin);
} while (fname < 0 || fname > 0);
getchar();
int hours=0;
int over_time=0;
int normal_pay=0;
int bonus=0;
int salary_deduct=0;
int education_tax=0;
int NHT_tax=0;
int NIS_tax=0;
int medical_dental=0;
int netpay=0;
int netpay1=0;
int netpay2=0;
int netpay3=0;
add_hours(&hours);
salaryselect(&hours,&salary_deduct,&normal_pay,&over_time,&bonus);
tax(&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&hours);
net_pay(&hours,&over_time,&normal_pay,&bonus,&salary_deduct,&education_tax,&NHT_tax,&NIS_tax,&medical_dental,&netpay,&netpay1,&netpay2,&netpay3);
}
int add_hours(int *hours)
{
int mo, tu, we, th, fr;
do
{
printf("Enter daily hours for Monday:\n");
scanf("%d",&mo);
if (mo < 0 || mo > 24)
{
printf("Invalid entry, please try again.\n\a \a\a");
}
fflush(stdin);
} while (mo < 0 || mo > 24);
do
{
printf("Enter daily hours for Tuesday:\n");
scanf("%d",&tu);
if (tu < 0 || tu > 24)
{
printf("Invalid entry, please try again.\n\a\a \a");
}
fflush(stdin);
} while (tu < 0 || tu > 24);
do
{
printf("Enter daily hours for Wednesday:\n");
scanf("%d",&we);
if (we < 0 || we > 24)
{
printf("Invalid entry, please try again.\n\a\a \a");
}
fflush(stdin);
} while (we < 0 || we > 24);
do
{
printf("Enter daily hours for Thursday:\n");
scanf("%d",&th);
if (th < 0 || th > 24)
{
printf("Invalid entry, please try again.\n\a\a \a");
}
fflush(stdin);
} while (th < 0 || th > 24);
do
{
printf("Enter daily hours for Friday:\n");
scanf("%d",&fr);
if (fr < 0 || fr > 24)
{
printf("Invalid entry, please try again.\n\a \a\a \a \a \a \a \a");
}
fflush(stdin);
} while (fr < 0 || fr > 24);
*hours=mo+tu+we+th+fr;
printf("\nThe weekly hours are:%d\n",*hours);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int salaryselect(int *hours,int *salary_deduct,int *normal_pay,int *over_time,int *bonus)
{
*normal_pay=*hours*20;
*over_time=(*hours-60)*40+*normal_pay;
*salary_deduct=*hours*20-*hours*10;
*bonus=*over_time+3000;
if(*hours<=40)
printf("\nThe employee is slacking and salary will be deducted!\nThe gross pay is:$%d dollars\n",*salary_deduct);
else if(*hours<=60)
printf("\nThe employee will get normal pay\nThe gross pay is:$%d dollars\n",*normal_pay);
else if(*hours<=70)
printf("\nThe employee is working over time and will get overtime pay\nThe gross pay is:$%d dollars\n",*over_time);
else
printf("\nTHE EMPLOYEE IS WORKING EXTREMELY HARD AND WILL GET A BONUS ON HIS PAY!\nThe gross pay is:$%d\n",*bonus);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
int tax(int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *hours)
{
*education_tax=*hours*20*.06;
printf("Education tax of %6:$-%d\n",*education_tax);
*NHT_tax=*hours*20*.1;
printf("NHT tax of %10:$-%d\n",*NHT_tax);
*NIS_tax=*hours*20*.05;
printf("NIS tax of %5:$-%d\n",*NIS_tax);
*medical_dental=*hours*20*.05;
printf("Medical/dental of %5:$-%d\n",*medical_dental);
}
int net_pay(int *hours,int *over_time,int *normal_pay,int *bonus,int *salary_deduct,int *education_tax,int *NHT_tax,int *NIS_tax,int *medical_dental,int *netpay,int *netpay1,int *netpay2,int *netpay3)
{
*netpay=*salary_deduct-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay1=*normal_pay-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay2=*over_time-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
*netpay3=*bonus-(*NHT_tax+*education_tax+*NIS_tax+*medical_dental);
if(*hours<=40)
printf("The net pay is:$%d\n",*netpay);
else if(*hours<=60)
printf("The net pay is:$%d\n",*netpay1);
else if(*hours<=70)
printf("The net pay is:$%d\n",*netpay2);
else
printf("The net pay is:$%d\n",*netpay3);
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
printf("\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
}
Fou-Lu
02-10-2010, 03:26 PM
This isn't right:
do
{
printf("Enter the employee's First Name AND DO NOT INPUT ANY ANY NUMBERS OR FOOLISHNESS:\n");
scanf(" %[^\n0-9]s ",fname);
if (fname < 0 || fname > 0)
{
printf("Invalid entry, please try again.\n\a \a\a");
}
fflush(stdin);
} while (fname < 0 || fname > 0);
First and foremost, fname needs to be a pointer. Declare it as a char *, not a char.
Next, you're error control is improper for a type of char *. Perhaps you're meaning to check the length of it to ensure its greater than 0? I believe its string.h that allows you to use strlen. Thats what you should be checking for, not twice for > and < 0.
zangetsu
02-10-2010, 09:39 PM
i want it to check for like if a number is entered then it will prompt back and say that a character should be entered instead when i get this last little thing my project will be complete
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.