Wage Code Problem

im just a beginner, how do i complete this so it works?

#include <iostream>
using namespace std;



void main()
{
double hourlyRate;
double hoursWorked;
double wages;
enterValues(&hourlyRate, &hoursWorked);
computeWages(&wages, hourlyRate, hoursWorked);
cout << "Your wages are: $" << wages << endl;
}
Write the funcitons.
im not sure how, thats the problem
First step: change void main() to int main and repost with code blocks. After you do this I will help you further.

//
#include <iostream>
using namespace std;

int main()
{
double hourlyRate;
double hoursWorked;
double wages;
enterValues(&hourlyRate, &hoursWorked);
computeWages(&wages, hourlyRate, hoursWorked);
cout << "Your wages are: $" << wages << endl;
}
//


im not sure what code blocks are. but i changed it to int main
now that your main is expecting to return an int, you should have it return 0; at the end of the program.

Also, your program needs the variables to be declared. That's a clue for the first function you need to write.

And how are the wages calculated? That's the clue for the second function.

Your program is all math, so it should be pretty simple for you to figure it out.
Last edited on
Aaaand in the event that you don't know how to write a function...
http://cplusplus.com/doc/tutorial/functions/
http://cplusplus.com/doc/tutorial/functions2/

EDIT: You'll also need the second link.

-Albatross
Last edited on
Lol! Well at least you tried. Start by declaring your functions in between using namespace std; and int main() you will want them to return double data types so they should be declared as doubles.

Inside of int main(){...}:
- Don't pass hourlyrate or hoursWorked to enterValues() this is silly. You should be prompting for these variables from inside the function.
- It would be better to call computeWages() from inside enterValues()
- Assign the value returned by computeWages to your variable wages inside of enterValues() and return that value to int main() where you again assign it to the wages variable inside of int main() and cout it to the console.
Last edited on
no clue whats going on. this is the first class on computer programming. And LITERALLY the teacher throws us this. i have no clue how to do this.
Did you get a book?

Usually if the prof does this, he's expecting you to read the book about the subject...

But anyways, if that main function is what the prof gave you to work with, I wouldn't make the suggested (and quite valid) changes Computergeek01 gave you.

But, we aren't really going to just TELL you the answer... cause that's just not kosher.

You can read the two tutorials that Albatross gave you, those will help with the building of the function, but the logic for the code inside will be in your text book.
haha perhaps it wouldnt be kosher, but id rather have the final outcome and then analyze it further on my own.
@Computergeek01:
1st: This is the assignment his teacher gave him. If his teacher tells him to implement it like that, he should implement it like that.
2nd: The enterValues method is probably a void type method specifically designed to get 2 double values. Actually, this is not bad design. It's probably a bit pointless here, but if you have to make more complex checks for the correctness of input this actually makes sense. (please notice that he passes pointers here, not the actual values)
3rd: No it would absolutely not be better to call computeWages from enterValues. Cause not everytime you enter values you want to compute wages (in this case, yes. But normally not).

To altima: I don't know how much you know about C++, but you will at least need to know about the following:

1. The basic structure of a C++ program.
2. iostream (particulary std::cout and std::cin).
3. Variables and Operators
4. Functions
5. Pointers

You can find all of these here: http://www.cplusplus.com/doc/tutorial/

If you have troubles understanding something, feel free to ask.
Last edited on
i would like the final code written out, with the original code and incluiding the functions. i jst need sumthing to go on. so having the final outcome would benefit me.
Sorry, but it probably wouldn't benefit you. Just look at the link I gave you, and read through those few pages. Not too much work, really. If you have already no Idea where to start, the full answer would confuse you at best. You would have something that works, but you still wouldn't know why it works.

(oh, and trust Albatross. There is an agreement amongst most of the members to not give full working code to people who show no attempt to solve their problems alone. We won't work for you, we will just help you to correct your mistakes).
Last edited on
i would like the final code written out, with the original code and incluiding the functions.

The elite and veterans here will never give you that. Sorry.

Check my links on how to write a function.

-Albatross
@hanst99:
1ST: I assumed the OP copied it from somewhere, or is working off of a previous project.
2ND: enterValues is not a void, it isn't anything because it isn't declared yet. The pointer thing doesn't make sense only keep them if it's part of the assignment like hanst99 said it is.
3RD: Yet everytime you run the program you are computing wages anyway... Logic Fail.

@altima08: For that to be done and legally considered your work you would have to hire one of us as a private contractor. Go ahead ask some of these guys what they charge.
Well,

no clue whats going on. this is the first class on computer programming. And LITERALLY the teacher throws us this. i have no clue how to do this.


I'm not gonna argue with you on this, and I already said that in might appear pointless in this case. If you A: need to make checks on the input and B: Need it more than once writing a function for the Input it makes sense to write a function for the Input. That way, if you are going to enhance the program later on it becomes easier to change stuff (for example, you might want to get the values from a text field instead of from the console, etc). (though in this case I don't really see why there is no function for the output. I don't know what the author of that code piece was thinking either, I can just guess).
Last edited on
Topic archived. No new replies allowed.