Write a program that will input the number of wins and losses that a baseball team acquired during a complete season. The wins should be input in a parameter-less value returning function that returns the wins to the main function. A similar function should do the same thing for the losses. A third value returning function calculates the percentage of wins. It receives the wins and losses as parameters and returns the percentage (float) to the main program which then prints the result. The percentage should be printed as a percent to two decimal places.
Sample Run:
Please input the number of wins
Please input the number of losses
#include <iostream>
#include <iomanip>
using namespace std;
// fucntion delcaration
int readwins();
int readlosses();
double calpercentWins(int,int);
int main(){
// read number of wins
int wins;
wins = readwins();
// read number of losses
int losses;
losses = readlosses();
//print wins percentage after rounding two decimal places
cout << "The percentage of wins is: " << setprecision(2) << percentWins <<" % " << endl;
system("pause");
return 0;
}
// reads and returns the number of wins
int readwins(){
int w;
cout << "Please input the number of wins:" << endl;
cin >> w;
return w;
}
// reads and returns the number of losses
int readlosses(){
int l;
cout << "Please input the number of losses:" << endl;
cin >> l;
return l;
}
// calculates and returns the percentage of wins
double calpercentWins(int wins,int losses){
double percent = (double)wins / (wins + losses) * 100;
return percent;
}
#include <iostream>
#include <iomanip>
usingnamespace std;
// fucntion delcaration
int readwins();
int readlosses();
double calpercentWins(int,int);
int main()
{
// read number of wins
int wins;
wins = readwins();
// read number of losses
int losses;
losses = readlosses();
// calculate the wins percentage
float percentWins;
//double percentWins;
percentWins = calpercentWins(wins,losses); // delete int
//print wins percentage after rounding two decimal places
cout << "The percentage of wins is: " << setprecision(2) << percentWins <<" % " << endl;
system("pause");
return 0;
}
// reads and returns the number of wins
int readwins(){
int w;
cout << "Please input the number of wins:" << endl;
cin >> w;
return w;
}
// reads and returns the number of losses
int readlosses(){
int l;
cout << "Please input the number of losses:" << endl;
cin >> l;
return l;
}
// calculates and returns the percentage of wins
double calpercentWins(int wins,int losses){
double percent = (double)wins / (wins + losses) * 100;
return percent;
}