Bonjour,

Je voudrais arriver a calculer le total des nombres flottant pour avoir comme résultat (exemple ici 50) , on m'a conseiller de faire une boucle avec comme opérateur += mais je sais pas comment je peut faire Merci D'avance.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
 
using namespace std;
 
//Fonction afficher
void affiche(const map<string, float> & facture)
{
 
  for (map<string,float>::const_iterator it=facture.begin(); it!=facture.end(); ++it)
  {
    cout << it->first << " = \t" << it->second << endl;
  }
}
 
int main()
{
 
  map<string,float> facture;
 
  facture["Chausson au pomme"] = 10;
  facture["Soupe"] = 15;
  facture["Thon"] = 10;
  facture["Haricot"] = 15;
 
  affiche(facture);
 
	return 0;
 
}