Hello everyone we have an assignment due tonight which involved creating a class and using functions within it to display a giftwrap invoice.
I have almost completed this assignment but am getting some identifier errors and function called missing arguments and plenty more. I am hoping someone out there who is a better programmer then me(not hard to find) can help me out.
First I need to know what can I do to pass values that one function calculates into another?
I need to pass the value subtotal into calctax, and then add calcsubtotal and calctax to get calctotal.
please help me out.
this code is part of my implementation file named giftwrap.cpp
For your example, call the function. Here is how I would do your code:
1 2 3 4 5 6 7 8 9 10 11 12
float giftWrap::calcSubTotal() {
// You can still do your way, I just put all the equations onto a single line
return 2 * (length*width - length*height - width*height) * pricePerInch;
}
float giftWrap::calcTax() {
return calcSubTotal() * taxRate;
}
float giftWrap::calcTotal() {
return calcSubTotal() + calcTax();
}
Also, in your original code, you line 8 is the wrong way round the equals sign (should give you an error like 'assigning to an rvalue').
Hi NT3 I switched my line 8 around, and did the return the way you recommended that and kbw's recommendation helped out. :) Thank you!
Now my implementation is free of errors. If possible can you explain how I could go about using a constructor that takes two arguments to instantiate a class object?
for example in my code:
this is my header file GiftWrap:
I want to use the 2nd constructor, "GiftWrap(float x, float y)" and instantiate a class object named sallys (this will be written in another cpp file with include "giftwrap.h")
Try looking up some tutorials on classes if you don't really understand, and even if you think you do, they can help to show you what you need to know anyway.
Thanks NT3 you are a godsend! lol. :) Any good tutorials you recommend? This is my first programming language btw so everything is kind of floaty but I'm sure I'll learn with practice. I'm using a book called A First Book of C++ by Bronson.
The ones on this site are pretty good. Also, I like the ones at learncpp (just look it up), they have a large number of examples to help you understand what is going on, and the contrasting style can bring other things to focus. And yes, the only way that anyone becomes good at anything is practice!