Hi guys,
I was doing an assignment for my oop class and needed help. My assignment is about creating an invoice program that calculates the invoice amount from taking the item quantity and price and multiplying them together. The quantity as of type integer while the price is of type float as requested in the question. The problem is when I return the invoice amount from multiplying the two i get them as an integer rather than as a float. Another problem is that even when i set the price to 100.00, it displays it as 100. The following is the implementation file. I even tried using the static_cast<float>() thing but its still not working. Any help is appreciated. Thanks.
The return type of your getInvoiceAmount function is of type int, whereas you intend to return as float. Change your function definition to:
float Invoice::getInvoiceAmount()
Otherwise, the compiler will automatically cast your float back to an int before returning the value. Returning it as a float should solve your problem.
But shouldnt it automatically take it as a float as it returns it as a float?
What is 'it'? If you mean cout, then the answer is, it does. It simply prints the value using the default settings. Since the default doesn't suit your needs, you need to specify what settings you would like.