Help with percentages

How do I deal with percentages?
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
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	int bases, doubles, triples;
	int homeruns, hits, singles; // declared integets
	
	cout << "Enter the amount of hits :";
	cin >> hits ;
	cout << "Enter the amount of doubles: ";
	cin >> doubles ; 
	cout << "Enter the amount of triples: ";
	cin >> triples ;
    cout << "Enter the amount of homeruns: ";
    cin >> homeruns ; // user input
    
    bases = singles + (doubles * 2) + (triples * 2) + (homeruns * 4); // calculates bases
    singles = hits - doubles - triples - homeruns; // calculates singles
    
    
    
    cout<< endl << endl
	     << "************************" << endl
         << "Total runs in the game" << endl 
         << "hits: " << hits << endl
         << "singles: " << singles << endl
         << "doubles: " << doubles << endl
         << "triples: " << triples << endl
         << "homeruns: " <<homeruns << endl
		 << "bases: " << bases << endl
		 << "************************" ; //displays baseball game stats
		 
return 0;		     
}
Where are you supposed to output percentages? What is the issue you're having?
Line 21 should be before line 20, you just cant use singles in you formula before defining it, it will produce garbage values
Topic archived. No new replies allowed.