Quote:
Why total payment/ not show up?
The real question was probably why the printReceipt() function doesn't output any meaningful values?
Let's see:
void printReceipt()
{
int payment, TPurc, qty, TPrice, Tcost;
cout << "***********************************************************************" << endl;
cout << " WELCOME TO SAN SPORTS " << endl;
cout << " NO.TEL : 012-3456789 " << endl;
cout << " ADDRESS : LOT67, JALAN 9, KAMPUNG JAYA, 45600, BESTARI JAYA, SELANGOR" << endl;
cout << "***********************************************************************" << "\n" << endl;
cout << "Total:RM " << TPrice << endl;
cout << "Your Discount: RM" << payment << endl;
cout << "Your Payment: RM" << Tcost << endl;
cout << "Total Purchase: RM" << TPurc << "\n" << endl;
cout << "************************" << "THANK YOU FOR COMING" << "***********************" << endl;
}
All variables are declared locally here and are therefore not uninitialized local variables. The compiler should also display this if you have configured it accordingly.
There are still some things we should address before a proposal for a solution would make sense. It is not common to declare functions locally in main(). I would recommend putting these either at the beginning of the source code, or in a separate header file.
There seems to be some problems with data types.
payment = calcMember();
warning C4244: "=": Conversion from "float" to "int", possible data loss
Since the variables payment and price obviously contain floating point numbers, it would make sense to declare them as float or double as well.
change to this:
float calcBad()
{
float price;
...
price = 32.00;
return price;
}
If the value 32.00 is actually to be stored in a variable without losing the decimal places, only a floating point number can be used.
To make the program a "real" C++ program, one solution would be to define all functions and data in one class.
It could look like this, for example:
class Paiment {
public:
float calcMember();
void printReceipt();
private:
float m_payment, m_TPurc, m_TPrice, m_Tcost;
int m_qty;
};
void Paiment::printReceipt()
{
...
}
The class-based variables can be identified with the addition m_ to avoid confusion. Now all local variables should be deleted and those already declared in the class should be used instead. Of course, at least one instance of the class should also be created in main().