473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help me with this program

32
Write a program that uses functions to calculate a person’s paycheck. The program should ask for a person’s first and last name, social security number (use fakes), phone number, address, hours worked (in the week), and hourly wage. The program should also include overtime (time and a half) if they have worked more than 40 hours. The program should also take out federal taxes (8%). The program should display the results to the screen. The program should run until the user chooses to quit. Have functions to do the following.
• Compute overtime for a person (for the given week).
• Compute federal tax on a person’s pay.
• Compute a person’s after-tax pay
All input and output should be done in main. The output should include the person’s first and last name, social security number, phone number, address, federal tax, and after-tax pay.
Turn in a design for this program at the beginning of the next lab.
• For each function, state what its parameters are, what it returns, and how it computes the returned value from the parameter values passed to it.
• List the steps in main, including function calls. Identify what is in the while loop. Indicate the condition for the while loop.
You will later modify this program so that, besides displaying the results to the screen, it will also write the information to a file called paycheck.dat.
Jan 25 '07 #1
11 1938
RedSon
5,000 Expert 4TB
No one is going to do your homework for you. Help us to help you by telling us what you have already done to solve this problem. Additionally if you are having problems writing your code, post a snippit of code in which you are having a problem. State what you think the problem might be and what ways you may be able to solve it. If there is a specific problem with your code that you cannot overcome, the nice folks on thescripts will help you.
Jan 25 '07 #2
Motoma
3,237 Expert 2GB
No one is going to do your homework for you. Help us to help you by telling us what you have already done to solve this problem. Additionally if you are having problems writing your code, post a snippit of code in which you are having a problem. State what you think the problem might be and what ways you may be able to solve it. If there is a specific problem with your code that you cannot overcome, the nice folks on thescripts will help you.
At least this one was clear, concise, and well formatted with proper english.
Jan 26 '07 #3
RedSon
5,000 Expert 4TB
At least this one was clear, concise, and well formatted with proper english.
That is the only reason I replied in the first place. Otherwise I would have just ignored the entire message. Ugh...
Jan 26 '07 #4
There could be errors with the code.. Couldnt compile an check it!!
Long an irritating code.. There were some ambiguities in your post, so couldnt render the entire code..

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #define F_TAX 0.08
  4.  
  5. int overtime(int);
  6. int federal(int);
  7.  
  8. void main()
  9. {
  10.  char f_name[20],ssn[20],addr[100],ch;
  11.  int phone_no,hours,hr_wage;
  12.  int overtime = 40,extra;
  13.  
  14.  printf("Enter your:\n");
  15.  printf("First name");
  16.  gets(f_name);
  17.  printf("\nsocial security no:");
  18.  gets(ssn);
  19.  printf("\naddress");
  20.  scanf("%s",addr);
  21.  printf("\nPhone no:");
  22.  scanf("%d",phone_no);
  23.  printf("\nHOurs u have worked:");
  24.  scanf("\nhours");
  25.  
  26.  printf("Press a key to continue:") ;
  27.  ch = getch();
  28.  
  29.  while(ch)
  30. {
  31.   clrscr();
  32.   break;
  33. }
  34.  
  35.  printf("The details u have entered are:");
  36.  printf("%s \t %s \t %s \t %d \t %d",f_name,ssn,addr,phone_no,hours);
  37.  // This is gettin to be a long program.. So i ve used tabs!! 
  38.  // Change the code the way u want your output to be displayed
  39.  
  40.  etra= overtime(hours) ;
  41.  printf("\nOvertime = %d"extra);
  42.  
  43. getch();
  44. }
  45.  
  46. int overtime(hours)
  47.  {
  48.   int extra;
  49.   if(hours>40) 
  50.     extra = hours - 40;
  51.     return extra; 
  52.  else
  53.    printf("You have not worked for extra hours!!");
  54.   }
  55.  
  56. int federal(pay)
  57.  {
  58.   // Calculations up to u.. I am not sure how tax is accounted for!
  59.   // Return values accordingly. The second and the third functions u have
  60.   // specified are more or less the same.. they can be implemented right her in
  61.   // this function itself!
  62.  } }
Jan 27 '07 #5
horace1
1,510 Expert 1GB
now compiles, see if it does what you require
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #define F_TAX 0.08
  4.  
  5. int overtime(int);
  6. int federal(int);
  7.  
  8. int main()
  9. {
  10.  char f_name[20],ssn[20],addr[100],ch;
  11.  int phone_no,hours,hr_wage;
  12.  int overtime = 40,extra;
  13.  
  14.  printf("Enter your:\n");
  15.  printf("First name");
  16.  gets(f_name);
  17.  printf("\nsocial security no:");
  18.  gets(ssn);
  19.  printf("\naddress");
  20.  scanf("%s",addr);
  21.  printf("\nPhone no:");
  22.  scanf("%d",phone_no);
  23.  printf("\nHOurs u have worked:");
  24.  scanf("\nhours");
  25.  
  26.  printf("Press a key to continue:") ;
  27.  ch = getch();
  28.  
  29.  while(ch)
  30. {
  31.   clrscr();
  32.   break;
  33. }
  34.  
  35.  printf("The details u have entered are:");
  36.  printf("%s \t %s \t %s \t %d \t %d",f_name,ssn,addr,phone_no,hours);
  37.  // This is gettin to be a long program.. So i ve used tabs!! 
  38.  // Change the code the way u want your output to be displayed
  39.  
  40.  extra= overtime *hours ;  // ** changed expression
  41.  printf("\nOvertime = %d", extra); // ** added ,
  42.  
  43. getch();
  44. }
  45.  
  46. int overtime(hours)
  47.  {
  48.   int extra;
  49.   if(hours>40) 
  50.     {       // ** added {
  51.     extra = hours - 40;
  52.     return extra; 
  53. }  // ** added
  54.  else
  55.    printf("You have not worked for extra hours!!");
  56.   }
  57.  
  58. int federal(pay)
  59.  {
  60.   // Calculations up to u.. I am not sure how tax is accounted for!
  61.   // Return values accordingly. The second and the third functions u have
  62.   // specified are more or less the same.. they can be implemented right her in
  63.   // this function itself!
  64.  } 
  65.  
Jan 27 '07 #6
Thanks buddy for doin the corrections required.. Its just that I was too bored to compile it and see, thanks anyways!
Jan 27 '07 #7
compsci
32
Im a beginner C++ programmer and I don't quite understand the code and how the program works. Please help me understand.
Jan 27 '07 #8
Ganon11
3,652 Expert 2GB
Im a beginner C++ programmer and I don't quite understand the code and how the program works. Please help me understand.
Which parts do you not understand?
Jan 27 '07 #9
Here s the new program. this is important !! Refer to this as u read my explanation in the next post. This is simplified compared to the previous script. That should help u!!

#include<stdio.h>
#include<conio.h>
#define F_TAX 0.08

int overtime(int hours)
{
int extra;
if(hours>40)
extra = hours - 40;
return extra;
else
printf("You have not worked for extra hours!!");
}

int federal(int pay)
{
// Calculations up to u.. I am not sure how tax is accounted for!
// Return values accordingly. The second and the third functions u have
// specified are more or less the same.. they can be implemented right her in
// this function itself!
}

void main()
{
char f_name[20],ssn[20],addr[100],ch;
int phone_no,hours,hr_wage;
int overtime = 40,extra;

printf("Enter your:\n");
printf("First name:");
scanf("%s",f_name);
printf("\nsocial security no:");
gets(ssn);// use scanf() as above!
printf("\naddress");
scanf("%s",addr);
printf("\nPhone no:");
scanf("%d",phone_no);
printf("\nHOurs u have worked:");
scanf("\nhours");

clrscr(); // clears screen

printf("The details u have entered are:");
printf("%s \t %s \t %s \t %d \t %d",f_name,ssn,addr,phone_no,hours);
// This is gettin to be a long program.. So i ve used tabs!! \t provides a tab space
// Change the code the way u want your output to be displayed

etra= overtime(hours) ;
printf("\nOvertime = %d"extra);

getch();
}
Jan 27 '07 #10
Hi.
Let me try explaining to you in the most simplest way. Hope you understand it. Infact I shall make you understand it!
Firstly, before you write any c or c++ program, most of the times you would be making use of predefined functions
all included in wat is referred to as Header files. eg. stdio.h and conio.h.
The extension .h indicates that the file is a header file and these header files can be included in the program you write
by using the #include directvie.

So the first two statements, #include<stdio.h> and #include<conio.h> include header files in your program. stdio.h contains the
fnction printf and scanf() definitions ad conio.h contains function definitions for getch();
Without includeing these header files, u would have compilation errors..

Next, check out the #define F_TAX = 0.08 statement. This statement makes the value of F_TAX available throughout the program.
You can also define this as a variable inside the main() loop as

int F_TAX = 0.08;

int suggests the datatype, indicates that the variable F_TAX shall hold integer value.

Similarly

char var_name;// indicates that the variable var_name shall hold a character.
eg. char ch; // refer program

char var_name[n]; // indicates that the var_name variable shall hold a string of length n; n = 1,2,3....
eg. char addr[100]; // refer program

next to display a string on the console, we use printf() function.

syntax: printf(" data to be displayed comes within quotes ");

Now if u have to print a value to the screen then,

printf("the integer value is: %d", var_name);
eg; printf("Your phone no is: %d", phone_no); // Prints the value in phone_no variable

To scan a value, that is to get user input and store it in a variable, use the function scanf()

syntax: scanf("%d", &phnoe_no); // would store the value inputted by user in the phone_no variable.
For now dont bother about the gets(). Use scanf everywhere and should you have to input a string and store it in
a variable, replace %d by %u and do not include the & character before the variable name as u did to store an integer value in the above example. this
is important!!!

Should you have to print a string of characters on the console, replace %d by %u! Simple isnt it??

By now I guess you can understand the main() function. next comes the functions we have written. I have written the program in a simpler method to help
you understand better. For now, write all functions before main(). See the new program.

synatx of a function:


return_data_type function_name(parameter_data_type parameter_name)
{
//function body
}

SImple, ain't it?

return type indicates a value returned to the main(). So in main(), you should have a variable to hold the returned value.

oofff.. This is tiring. Anyways, I ll hurry up a bit!

consider as an example:

int overtime(int hours) // refer new program
{
int extra; // A variable inside and available only for this function
if(hours>40)// Check if you have worked for more than 40hrs, if yes execute for loop else donot execute for loop
{
extra = hours - 40; // Calculate how many extra hours, say for eg, i ve worke 100 hrs, then extra will have 60!!
return extra;// send value 60 in extra to main() function
}
else
printf("You havent worked extra hours");

}

To hold the returned value, I have a variable named new_var in main function, print the value in new_var..

Calling a function from wihin main is simple. In order to call overtime function,

new_var = overtime(hours);

new_var holds returned value and the parameter i am passing to overtime function is hours.

Wow!!! I am tired, guess u too would be tired reading this. I ve tried my best to help u understand. Let me know if this helped u.

regards
Cyberking..
Jan 27 '07 #11
compsci
32
Yes thanx. I got a better understanding
Jan 27 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
5
by: Bec | last post by:
I'm in desperate need of your help.. I need to build an access database and have NO idea how to do this.. Not even where to start.. It IS for school, and am not asking anyone to do my...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
1
by: Willing 2 Learn | last post by:
Below is a program I did to recognize a Finite State Automata for ASCII (J+H)*. I got that one working but im having trouble getting the NFA program to work. I really desperately need help! My...
4
by: Bob Homes | last post by:
In VB6, I used a system, which I loved, whereby I assigned a "helpId" to each menu item; that way, you could rest the cursor on the item (without actually running it) and then press F1 to get...
2
by: Bsnpr8 | last post by:
I need help guys, i have to many stuff to do, because i am in my last 2 weeks of the university, my last assignment is to do a spell checker in C++, i have an idea but nothing is coming out. I really...
6
by: HelpME | last post by:
I wrote a program in Vb.Net that was running fine. However I am unable to install it on a couple of machines. When i run it I get a windows error message that says My Project.exe has...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.