-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle.cpp
60 lines (44 loc) · 1.07 KB
/
handle.cpp
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
#include <iostream>
#include <vector>
#include <string>
#include <stdexcept>
using namespace std;
void displayMean(vector<double> notes);
int main()
{
string line;
vector<double> v;
double note;
int counter = 0;
while (true){
cout << "Entrer la note n°" << counter+1 << ": ";
getline(cin, line);
if (line.empty()){
displayMean(v);
break;
}
try{
note = stod(line);
if (note < 0 || note > 20){
displayMean(v);
break;
}
}
catch (const invalid_argument & ia){
displayMean(v);
break;
}
v.push_back(note);
counter++;
}
return 0;
}
void displayMean(vector<double> notes){
double sum = 0.0;
size_t size_array = notes.size();
if (size_array == 0) cout << "Pas de notes enregistrées" << endl;
else{
for (size_t i=0; i<size_array; i++) sum += notes.at(i);
cout << "La moyenne est de " << sum/size_array << endl;
}
}