Cours:TdC : Différence entre versions
(Page créée avec « <source lang=c> #include <iostream> using namespace std; int main() { float prix; float total=0; do { cout << "Saisir prix" << endl; cin >> prix; t... ») |
m |
||
| Ligne 7 : | Ligne 7 : | ||
float prix; | float prix; | ||
float total=0; | float total=0; | ||
| + | float r=0; | ||
| + | float prixMin=999999,prixMax=0; | ||
do | do | ||
{ | { | ||
cout << "Saisir prix" << endl; | cout << "Saisir prix" << endl; | ||
cin >> prix; | cin >> prix; | ||
| + | if (prix>0) | ||
| + | { | ||
| + | if (prix>prixMax) prixMax=prix; | ||
| + | if (prix<prixMin) prixMin=prix; | ||
| + | } | ||
total=prix+total; | total=prix+total; | ||
} while(prix!=0); | } while(prix!=0); | ||
| − | cout << "Prix total :" << total <<endl; | + | // Calcul de la remise |
| + | if (total>999) {r=total*0.3;} | ||
| + | else if (total>499) {r=total*0.2;} | ||
| + | else if (total>99) {r=total*0.1;} | ||
| + | else {r=0;} | ||
| + | //Affichage | ||
| + | cout << "Prix total avant réduction:" << total <<endl; | ||
| + | cout << " Montant de la réduction:" << r <<endl; | ||
| + | cout << " A payer :" << total-r<<endl; | ||
return 0; | return 0; | ||
} | } | ||
</source> | </source> | ||
Version du 24 novembre 2015 à 08:07
#include <iostream>
using namespace std;
int main()
{
float prix;
float total=0;
float r=0;
float prixMin=999999,prixMax=0;
do
{
cout << "Saisir prix" << endl;
cin >> prix;
if (prix>0)
{
if (prix>prixMax) prixMax=prix;
if (prix<prixMin) prixMin=prix;
}
total=prix+total;
} while(prix!=0);
// Calcul de la remise
if (total>999) {r=total*0.3;}
else if (total>499) {r=total*0.2;}
else if (total>99) {r=total*0.1;}
else {r=0;}
//Affichage
cout << "Prix total avant réduction:" << total <<endl;
cout << " Montant de la réduction:" << r <<endl;
cout << " A payer :" << total-r<<endl;
return 0;
}