All pastes #942174 Raw Edit

Someone

public text v1 · immutable
·published 2008-03-14 09:38 UTC
rendered paste body
/*
  ------------------------------------------------------------------------------
  Fichier      : Labo3.cpp
  Auteur(s)    : Francesco Fuino et Sébastien Keller
  Date         : 11/03/08
  
  But          :
  
  Remarque(s)  :
  
  Compilateur  : gcc
  ------------------------------------------------------------------------------
*/

#include <iostream>

#define EVER ;;
#define SAISIE_UTILISATEUR 1
#define ETAT_INITIAL 2
#define LECTURE_NOMBRE 3
#define FIN_LECTURE_NOMBRE 4
#define AFFICHAGE 5
#define ERREUR_SAISIE 6
#define QUITTER_PROGRAMME 7


using namespace std;

int main( )
{
	unsigned short etat = SAISIE_UTILISATEUR;
	bool nonFin = true;
	bool premierNombre = true;
	char charLu;
	unsigned int nombreLu, nombreCourant, nombreAffiche;
	unsigned short compteurNombreCourant = 1;
	
	
	do {
		
		switch (etat) {
			
			case SAISIE_UTILISATEUR :
				cout << "Entrez une sequence de nombres : "; 
				
				
			case ETAT_INITIAL :
				do
						cin.get(charLu);
				while (isspace(charLu));
				
			case LECTURE_NOMBRE :
				nombreLu = 0;
				
				while (!isspace(charLu) && isdigit(charLu)) {
					
					nombreLu = nombreLu * 10 + int(charLu) - int('0');
					cin.get(charLu);
					
				}
				
				if (!isdigit(charLu) && !isspace(charLu)) {
					etat = ERREUR_SAISIE;
					break;
				}

				
			case FIN_LECTURE_NOMBRE :
				if (premierNombre) {
					nombreCourant = nombreLu;
					premierNombre = false;
					etat = ETAT_INITIAL;
					break;
					}
				else {
					if (nombreLu == nombreCourant) {
						compteurNombreCourant++;
						etat = ETAT_INITIAL;
						break;
					}
					else {
						nombreAffiche = nombreCourant;
						nombreCourant = nombreLu;	
					}		
				}
				
			case AFFICHAGE :
				cout << endl << compteurNombreCourant << "x" << nombreAffiche;
				compteurNombreCourant = 1;
				etat = ETAT_INITIAL;
				break;
			case ERREUR_SAISIE :
			case QUITTER_PROGRAMME :
				cout << endl << "Voulez vous quitter le programme [o/n] : ";
				while (cin.get() != '\n');
				cin.get(charLu);
				if (charLu == 'n') {
					etat = SAISIE_UTILISATEUR;
					while (cin.get() != '\n');
				}
				else
					nonFin = (charLu != 'o');
				break;
			
		}
		
	} while (nonFin);
	
	cout << endl << endl;
	system("PAUSE");
    return 0;
}