I am writing a c++ program where i need to call a private member function from main function. Please look at my code:
#include <iostream>
using namespace std;
class cricket
{
private:
int target_score;
int overs_bowled;
int extra_time;
int penalty;
void cal_penalty()
{
if(extra_time <=10)
penalty = 1;
else if(extra_time <=20)
penalty = 2;
else
penalty = 5;
}
public:
void extradata()
{
cout << "\nEnter Target Score : ";
cin >>target_score;
cout <<"\nEnter Overs bowled : ";
cin >> overs_bowled;
cout << "\nEnter extra time : ";
cin >> extra_time;
}
void displaydata()
{
cout << "\nTarget Score : "<< target_score;
cout << "\nOvers Bowled: " << overs_bowled;
cout << "\nExtra Time : " << extra_time;
cout << "\nPenalty : " <<penalty;
}
};
int main()
{
cricket c1;
c1.extradata();
c1.displaydata();
return 0;
}
Here i am getting all the output correctly but i am confused how to display the value of penalty after checking the extratime. Please edit my program so that i can get the value of penalty based on the input of extra time