Exemples langages
67
C++
#include
using namespace std ;
main()
{ float montant, taux, remise ;
cout << "donnez le montant brut : " ;
cin >> montant ;
if (montant < 2000.)
taux = 0. ;
else if (montant <= 5000.) taux = 1. ;
else
taux = 2. ;
remise = montant * taux/100. ;
montant = montant - remise ;
cout << "montant après remise : " << montant ;
}
donnez le montant brut : 3000
montant après remise : 2970
Java
public class Facture
{ public static void main (String args[])
{ double montant, taux, remise ;
System.out.print ("donnez le montant brut : ") ;
montant = Clavier.lireDouble () ;
if (montant < 2000.)
taux = 0. ;
else if (montant <= 5000.) taux = 1. ;
else
taux = 2. ;
remise = montant * taux/100. ;
montant = montant - remise ;
System.out.println ("montant après remise : " + montant) ;
}
}
donnez le montant brut : 3000
montant après remise : 2970
Notez que les constantes telles que 1. sont de type double (et non float). Si nous avions déclaré taux
de type float, l’affectation :
taux = 1.
serait interdite car elle demanderait une conversion implicite du type double vers le type float.
Précédent

- 90/370

Suivant