/home/manu/Dropbox/Projets/complexes/main.cpp
#include <iostream>
#include <iomanip>
using namespace std;

struct Complexe
{
    double reel, imaginaire;
};

int main()
{
    Complexe x={0,0}, y={0,0}, addition, soustraction;
    unsigned choix;

    cout << setprecision(4);

    do {
        addition.reel = x.reel + y.reel;
        addition.imaginaire = x.imaginaire + y.imaginaire;
        soustraction.reel = x.reel - y.reel;
        soustraction.imaginaire = x.imaginaire - y.imaginaire;

        cout << "----------------------------------" << endl;

        cout << "X   = " << x.reel << (x.imaginaire>=0.0 ? "+" : "") << x.imaginaire << "i" << endl;
        cout << "Y   = " << y.reel << (y.imaginaire>=0.0 ? "+" : "") << y.imaginaire << "i" << endl;

        cout << "X+Y = " << addition.reel << (addition.imaginaire >= 0.0 ? "+" : "")
             << addition.imaginaire << "i" << endl;

        cout << "X-Y = " << soustraction.reel << (soustraction.imaginaire >= 0.0 ? "+" : "")
             << soustraction.imaginaire << "i" << endl;

        cout << "----------------------------------" << endl;
        cout << "Changer le nombre complexe X ... 1" << endl;
        cout << "Changer le nombre complexe Y ... 2" << endl;
        cout << "Quitter le programme ............0" << endl;
        cout << "----------------------------------" << endl;
        cout << "Votre choix : "; cin >> choix;
        switch (choix)
        {
        case 1 :
            cout << "Partie réelle = ";
            cin >> x.reel;
            cout << "Partie imaginaire = ";
            cin >> x.imaginaire;
            break;
        case 2 :
            cout << "Partie réelle = ";
            cin >> y.reel;
            cout << "Partie imaginaire = ";
            cin >> y.imaginaire;
            break;
        case 0 :
            cout << "Au revoir !" << endl; break;
        default:
            cout << "Choix incorrect !" << endl; break;
        }
    }
    while (choix!=0);

    return 0;
}