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
| using System;
namespace exFonction3
{
class Program
{
// fonction utilisé dans le programme
static string gestionSaisie(string message, string valide1, string valide2)
{
string choix = "";
bool correct = false;
while (correct != true || choix != valide1 && choix != valide2)
{
try
{
Console.WriteLine(message);
choix = Console.ReadLine();
correct = true;
}
catch
{
Console.WriteLine("Entrez un \"O\" pour oui ou un \"N\" pour non");
}
}
return choix;
}
static void Main(string[] args)
{
int prix = 0, somme = 0;
string choixLocal = "";
string valide1 = "O";
string valide2 = "N";
choixLocal = gestionSaisie("Avez-vous un prix à saisir ? \"O\" : oui | \"N\" : non ", valide1, valide2);
while (choixLocal == "O")
{
Console.WriteLine("Entrez votre prix : ");
prix = int.Parse(Console.ReadLine());
somme = somme + prix;
choixLocal = gestionSaisie("Voulez vous resaisir un prix ? \"O\" : oui | \"N\" : non", valide1, valide2);
}
if (somme != 0)
{
Console.WriteLine("La somme des prix est : " + somme);
Console.WriteLine("Fin du programme");
}
else
{
Console.WriteLine("Fin du programme");
}
Console.ReadLine();
}
}
} |
Partager