C++ code

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();

// calculate the wins percentage
float percentWins;
percentWins = calpercentWins(int wins,int losses);

//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;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

#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();
	
	// 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;
}
num 22 line
delete int
Topic archived. No new replies allowed.