writing clean code

I've written this code but as you can see it's messy. Any tips on how I can make it better? Thanks

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	vector<string> injuries(8);
	vector<int> prices(8);

	string name;
	double employeeId;
	int cases = 0;
	int sumOfPrices = 0;
	int injuryCount = 0;
	vector<int> listOfInjuries(20);

		injuries[0] = "Severe Abrasions and Bruising";
		injuries[1] = "Cuts w/Stiches";
		injuries[2] = "1st Degree Fractures";
		injuries[3] = "2nd Degree Fractures";
		injuries[4] = "Burn Treatment (all degrees)";
		injuries[5] = "Severed Appendage (Fingers/Toes)";
		injuries[6] = " Severed Appendages (Arms/Legs)";
		injuries[7] = "Concussion";


		prices[0] = 20;
		prices[1] = 60;
		prices[2] = 150;
		prices[3] = 350;
		prices[4] = 200;
		prices[5] = 180;
		prices[6] = 430;
		prices[7] = 45;

	cout << "Please enter the patient's first and last name: ";
	getline(cin, name);
	cout << "Please enter employee ID: ";
	cin >> employeeId;

	while (cases != 8) 
	{
	cout << injuries[0] << "\t - Type '0' " << endl;
	cout << injuries[1] << "\t - Type '1' " << endl;
	cout << injuries[2] << "\t - Type '2' " << endl;
	cout << injuries[3] << "\t - Type '3' " << endl;
	cout << injuries[4] << "\t - Type '4' " << endl;
	cout << injuries[5] << "\t - Type '5' " << endl;
	cout << injuries[6] << "\t - Type '6' " << endl;
	cout << injuries[7] << "\t - Type '7' " << endl;
	cout << "No other injuries" << "\t - Type '8' " << endl;
	cin >> cases;

	if (cases > 8 || cases < 0)
	{
	cout << "Enter a valid number!" << endl; 
	cout << injuries[0] << "\t - Type '0' " << endl;
	cout << injuries[1] << "\t - Type '1' " << endl;
	cout << injuries[2] << "\t - Type '2' " << endl;
	cout << injuries[3] << "\t - Type '3' " << endl;
	cout << injuries[4] << "\t - Type '4' " << endl;
	cout << injuries[5] << "\t - Type '5' " << endl;
	cout << injuries[6] << "\t - Type '6' " << endl;
	cout << injuries[7] << "\t - Type '7' " << endl;
	cout << "No other injuries" << "\t - Type '8' " << endl;
	cin >> cases;
	}

	sumOfPrices = sumOfPrices + prices[cases];
	
	 listOfInjuries[injuryCount]=cases;
	
	injuryCount++;
}
	if (injuryCount - 1 > 5)
	{
	    sumOfPrices = sumOfPrices - sumOfPrices * 0.10;
	    
	}
	
	cout << endl;
	cout << "Patients name: " << "\t" << name << endl;
	cout << "Employee ID: " << "\t" << employeeId << endl;
	cout << "Total number of injuries: " << injuryCount - 1 << endl;
	cout << "Total cost per injury: " << "\t" << sumOfPrices << endl;
	
	for (int displayCount = 0; displayCount < injuryCount -1; displayCount++)
	{
	    int list = listOfInjuries[displayCount];
	    
	    cout << injuries[list] << endl;
	    cout << prices[list] << endl;
	    
	    }
	    
	cin.sync();
    getchar();
    return 0;
}
1
2
cin.sync();
getchar();
Should not be used. cin.sync() behavior is very vague. So in certain implementations it might not do anything at all: http://ideone.com/AR8lB

Use consistent identation.

Use initialization lists to initialize your vector and group injure name and cost together in some data structure:
1
2
3
4
5
6
    const std::array<std::pair<std::string, int>, 8> injuries = {{
        {"Severe Abrasions and Bruising",   20}, {"Cuts w/Stiches",                    60},
        {"1st Degree Fractures",           150}, {"2nd Degree Fractures",             350},
        {"Burn Treatment (all degrees)",   200}, {"Severed Appendage (Fingers/Toes)", 180},
        {"Severed Appendages (Arms/Legs)", 430}, {"Concussion",                        45}
    }};
Thank, I appreciate you sharing your knowledge. Also, we use cin.sync(); and getchar(); because the console closes right away without it.
Also, we use cin.sync(); and getchar(); because the console closes right away without it.
Configure your IDE properly. Also:
http://www.cplusplus.com/forum/beginner/1988/
Topic archived. No new replies allowed.