-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharrays.cpp
More file actions
48 lines (33 loc) · 945 Bytes
/
arrays.cpp
File metadata and controls
48 lines (33 loc) · 945 Bytes
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
#include <iostream>
#include <array>
using namespace std;
int main()
{
//double cricketScore[7]; we can do like this but the formal way to do is below ie array container class
array <double, 7> cricketScore;
cricketScore[0] = 292;
cricketScore[1] = 323;
cricketScore[2] = 400;
cricketScore[3] = 230;
cricketScore[4] = 500;
cricketScore[5] = 60;
cricketScore[6] = 490;
//cricketScore.at(7) = 990; causes run time error, because we allocated space for 7 index this particular index is not associated with that array.;
// for(int i = 0; i < 7; i++)
for(size_t i = 0; i < cricketScore.size(); i++)
{
cout << cricketScore[i]<< endl;
}
// for(int i = 0; i < 7; i++)
for(size_t i = 0; i < cricketScore.size(); i++)
{
cout << "enter a score" << endl;
cin >> cricketScore[i];
}
// for(int i = 0; i < 7; i++)
for(size_t i = 0; i < cricketScore.size(); i++)
{
cout << cricketScore[i]<< endl;
}
return 0;
}