The sample output for member which is, works fine:
Please input a one if you are a member of the dental plan
Input any other number if you are not
1
Please input the service charge
7.89
Please input the test charges
89.56
The total bill is $97.45.
Whereas the sample output for non-member, gives me an output of 1.79214e-307 instead of 165.84
Sample output for non-member:
Please input a one if you are a member of the dental plan
Input any other number if you are not
2
Please input the service charge
75.84
Please input the test charges
49.78
Please input the medicine charges
40.22
The total bill is $165.84
Here's the code
#include <iostream>
using namespace std;
double totalmember( double serv, double test)
{
double total;
total = serv + test;
return total;
}
double totalnot( double serv, double test, double med)
{
double total;
total = serv + test + med;
return total;
}
int main()
{
int memberstat;
double servcharge, testcharge, medcharge , membertot, notmemtot;
cout << "Please input a one if you are a member of the dental plan" << endl;
cout << "Input any other number if you are not" << endl;
cin >> memberstat;
cout << endl;
cout << "Please input the service charge" << endl;
cin >> servcharge;
cout << "Please input the test charges" << endl;
cin >> testcharge;
if (memberstat != 1)
{
cout << "Please input the medicine charges" << endl;
cin >> medcharge;
}
if (memberstat == 1)
{
membertot = totalmember(servcharge, testcharge);
cout << "The total bill is $" << membertot;
}
else {
notmemtot = totalnot(servcharge, testcharge, medcharge);
cout << "The total bill is $" << membertot;
}
return 0;
}
How do I fix this?