#include <iostream> #include <iomanip> using namespace std; int main() { int acc
ID: 3582279 • Letter: #
Question
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int accountNumber;
float minimumBalance, currentBalance;
char accountType;
const float SAVINGS_PENALTY_CHARGE = 10.00;
const float CHECKING_PENALTY_CHARGE = 25.00;
const float SAVINGS_INTEREST_RATE = 0.1;
const float CHECKING_LOW_INTEREST_RATE = 0.20;
const float CHECKING_DEFAULT_INTEREST_RATE = 0.05;
double calculateBill(int income, int consultingMinutes, double hourlyRate);
int main();
int income, consultingMinutes;
double hourlyRate;
cout << "Please enter the clients income: $" ;
cin >> income;
cout << "Please enter the consulting time in minutes: ";
cin >> consultingMinutes;
cout << "Please enter the hourly rate: $";
cin >> hourlyRate;
cout << fixed << showpoint << setprecision(2);
cout << "Your total bill ammount comes to: $" << calculateBill(income, consultingMinutes, hourlyRate) << endl;
return 0;
}
double billingAmount;
double desiredPayment;
double penalty;
double credit;
double unpaidBalance;
double calculateBill(int income, int consultingMinutes, double hourlyRate){
if (income <= 25000) //If a person has a low income (<== 25,000)
if (consultingMinutes <= 30) //and the consulting time is less than or equal to 30 minutes, then there are no charges
return 0;
else
return hourlyRate * 0.40 * ((consultingMinutes - 30) / 60); //The service charges are 40% of the billing amount for the time over 30 minutes
if (consultingMinutes <= 20) // If the consulting time is less than or equal to 20 minutes, then there are no service charges
return 0;
else
return hourlyRate * 0.70 * ((consultingMinutes - 20) / 60); // The service chargess are 70% of the regular hourly rate for the time over 20 minutes
if( unpaidBalance = billingAmount - desiredPayment);
else {
unpaidBalance = unpaidBalance + penalty;
}
}
My program build and ran, but my output wasn't correct. For some reason it calculates to $0.00. I would really appreciate the help!
Explanation / Answer
1. consultingMinutes in an integer
2. So for any expression of the form ((consultingMinutes - 30) / 60) will computer to 0 if the value is not greater than 1
3. In the above case if consultingMinutes is less than 90 , above expression will compute to 0 .
Similarly for ((consultingMinutes - 20) / 60) computes to 0 if consultingMinutes is less than 80
4. You can change all such expressions to ((double)(consultingMinutes - 30) / 60) // called as type casting or change consultingMinutes to double type .
Some more pointers to your code :
The 20 minute check should be the first check .
If under completion it's ok otherwise , the following code is unreachable
if( unpaidBalance = billingAmount - desiredPayment);
else {
unpaidBalance = unpaidBalance + penalty;
}
Try to use an if else ladder for the entire set of checks rather than two different groups of if-else . Makes it easier to understand . Also use indentation and bracing where necessary for redability .
All The Best !!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.