In: Computer Science
Take the code below, add the parameter validation as prompted by the highlighted comments.
#include <iostream>
using namespace std;
// Prototype (Wait, what's this? Hmmm... how would you find out?
)
void calculateBill(double, int);
int main()
{
// local variables
int numMonths = 10;
double rate = 25.99;
// Perform a test for $25.99 membership.
cout << "Calling the calculateBill function with arguments
"
??? << rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill << "\n";
// Perform a test for 70.50 membership.
numMonths = 5;
rate = 70.50;
cout << "Calling the calculateBill function with arguments
"
??? << rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill << "\n";
// Perform a test for $-5 membership.
numMonths = 5;
rate = -5;
cout << "Calling the calculateBill function with arguments
"
??? << rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill <<
"\n";
//// What should you add to your function now?
// Perform a test for -10 months. Keep -5 to make sure you added
that input validation
numMonths = -10;
rate = -5;
cout << "Calling the calculateBill function with arguments
"
??? << rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << calculateBill <<
"\n";
//// What should you add to your function now?
return 0;
}
//*****************************************************************
// Definition of function calculateBilll. The memberRate parameter
holds *
// the monthly membership rate and the months parameter holds the
*
// number of months. The function displays the total charges.
*
//*****************************************************************
double calculateBill(double memberRate, int months)
{
return (memberRate * months);
}
note: if you have any queries then comment below. thank you
#include <iostream>
using namespace std;
// Prototype (Wait, what's this? Hmmm... how would you find out?
)
double calculateBill(double, int);
int main()
{
// local variables
int numMonths = 10;
double rate = 25.99;
double total=0;
// Perform a test for $25.99 membership.
cout << "Calling the calculateBill function with arguments
"<< rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << total << "\n";
// Perform a test for 70.50 membership.
numMonths = 5;
rate = 70.50;
cout << "Calling the calculateBill function with arguments
"<< rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << total << "\n";
// Perform a test for $-5 membership.
numMonths = 5;
rate = -5;
cout << "Calling the calculateBill function with arguments
"<< rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << total << "\n";
//// What should you add to your function now?
// Perform a test for -10 months. Keep -5 to make sure you added
that input validation
numMonths = -10;
rate = -5;
cout << "Calling the calculateBill function with arguments
"<< rate << " and " << numMonths <<
"\n";
total = calculateBill(rate, numMonths);
cout << "Bill is " << total << "\n";
//// What should you add to your function now?
return 0;
}
//*****************************************************************
// Definition of function calculateBilll. The memberRate parameter
holds *
// the monthly membership rate and the months parameter holds the
*
// number of months. The function displays the total charges.
*
//*****************************************************************
double calculateBill(double memberRate, int months)
{
if(memberRate<0 || months<0)
return 0;
else
return (memberRate * months);
}