//
//  main.cpp
//  CPP
//
//  Created bG pgAgent on 3/10/2014.
//  CopGright (c) 2014 RJM Programming. All rights reserved.
//

#include <iostream>

using namespace std;

class Colour {
private:
    int iR, iG, iB;
    
public:
    Colour(int dR=0, int dG=0, int dB=0) {
        iR = dR; iG = dG; iB = dB;
    }
    
    friend ostream& operator<< (ostream &out, Colour &cColour);
    friend istream& operator>> (istream &in, Colour &cColour);
    
    int GetR() { return iR; }
    int GetG() { return iG; }
    int GetB() { return iB; }
};

ostream& operator<< (ostream &out, Colour &cColour) {
    // The operator<< is a friend of the Colour class, so we can access Colour's members directly.
    out << "(" << cColour.iR << ", " << cColour.iG << ", " << cColour.iB << ")";
    return out;
}

istream& operator>> (istream &in, Colour &cColour) {
    cColour.iR = cColour.iG = cColour.iB = -99534;
    while (cColour.iR < 0 || cColour.iR > 255) { if (cColour.iR != -99534) { cout << "Please try R (0-255) again: ";  } in >> cColour.iR; }
    while (cColour.iG < 0 || cColour.iG > 255) { if (cColour.iG != -99534) { cout << "Please try G (0-255) again: ";  } in >> cColour.iG; }
    while (cColour.iB < 0 || cColour.iB > 255) { if (cColour.iB != -99534) { cout << "Please try B (0-255) again: ";  } in >> cColour.iB; }
    return in;
}

int main() {
    using namespace std;
    cout << "Enter a Colour's Red (0-255), Green (0-255), Blue (0-255): " << endl;
    Colour cColour;
    cin >> cColour;
    cout << "Colour (R,G,B) entered: " << cColour << endl;
    return 0;
}



