Algarithm for gross pay

Hi all, I am completly new to the c programing. So I appologize in advance if I sound programming illiterate:). I am having to create a algarithm that will determine the gross pay of a particular employee. I have to read the hourly rate, and the amount of hours worked by the employee. I have to display the hours, hourly rate, and the gross pay of the employee. If the hours exceed 40 compute, the overtime will be paid 1.5*hourly rate.

Every time I write a code for this it says that I have build errors and will not compile. At this point I am so frustrated and don't even know what it is supposed to look like, because I can not get anyting to work at all. Even when I put in a break point to see if anything works it doesnt. :(

Can someone please help!!!! I guess it would be safe to say explaining it to me like I'm in kindigarden would work best.

Thanks
There are lots of different ways you could do this, but I would just keep it simple and go with something like this. Here's pseudocode for it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
main function

double hourly_rate
print "Please input the hourly wage of the employee: "
input hourly_rate

int hours
print "Please input the number of hours worked by the employee: "
input hours

double gross_pay

if hours <= 40
gross_pay = hours * hourly_wage

else
gross_pay = (40 * hourly_wage) + ((hours - 40) * hourly_wage * 1.5)


Does that work for you?
yes thank you so much. I wrote it out how you had it and it had a few errors but I fixed them and I got it down to one error with the else statment. It is saying that it is illegal because it does not match the if statement and that it is expecting a statement. I'm sure I will get it figured out though. Thank you sooooo much you have no idea how much this helped me.
No problem! If you want to post your code I can probably let you know what's wrong. Just paste it between the tags code and /code, both with [] around either side of them.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#include <stdio.h>
#include <stdlib.h>
main() {
	double hourly_rate;
	double hours;
	double gross_pay;
	   printf("Please input the hourly rate of the employee:");
	   printf("Please input the number of hours worked by the employee:");
	
	   
	if(hours <= 40);
	{  
		printf("gross_pay = hours*hourly_rate");
	}

    else
	{
       gross_pay = (40*hourly_rate)+(hours-40)*(hourly_rate*1.5);
	}


  system("pause");
}
There's nowhere in your code that you initialize any of your variables. You're on the right track, but you need to use cin to values into your variables. Also, get rid of the print statement inside of your if statement. You don't want to print that, you want your program to use that algorithm to calculate gross_pay. Here's how I would right this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main() 
{
	double hourly_rate;
	double hours;
	double gross_pay;
	printf("Please input the hourly rate of the employee: ");
	cin >> hourly_rate;
	printf("Please input the number of hours worked by the employee: ");
	cin >> hours;
		   
	if(hours <= 40)
	{  
		gross_pay = hours * hourly_rate;
	}
	else
	{
		gross_pay = (40 * hourly_rate) + (hours - 40) * (hourly_rate * 1.5);
	}

	cout << "The gross pay of this employee is $" << gross_pay << "." << endl;

  system("pause");
  return 0;
}
Alright, I'm going to go through your code and tell you exactly what's wrong. First of all, Line 4: your main function is an int in c++. So, it needs to be written int main(). Second, you need to use cin to give hourly_rate and hours values. Line 12: your if statement can't have a semicolon after it. Generally, if you're putting braces after something (like with a function), it's not going to have a semicolon at the end of the line. That's why your else statement wasn't working. Also, line 14: all that line does is print out what you typed. Just get rid of the printf, parentheses, and quotes and you're good. After all that, I just added a print statement to show the calculations.
Oh, also, since main() is a function, it needs to return something. Since it's an int, it's easiest just to have it return 0, as you can see in my line 29.
Andddd, I'm assuming you really want c++, not c (as you posted in your question). If you actually wanted c, sorry about that. I don't know c very well, and everything I just told you, as well as the code I wrote above, is c++.
ok ill keep working on it thanks so much for all your help:)
yeah sorry I meant to say c++ lol. I am horrible at this I really don't know what I'm talking about. I need to look into getting a book on c++ with lots of tutorials in it. Im going to try and fix all of this stuff and see if it works out.
Topic archived. No new replies allowed.