cleaned all trailing white space from source files.
[sdk] / installer / coursework / Chapter 5 - Structures and Enumerations / Lab5 / colors / lab5colors.ec
1 #include <stdio.h>
2
3 enum KnownColor
4 {
5    black   = 0,
6    red     = 0xFF0000,
7    green   = 0x00FF00,
8    blue    = 0x0000FF,
9    yellow  = 0xFFFF00,
10    magenta = 0xFF00FF,
11    cyan    = 0x00FFFF,
12    white   = 0xFFFFFF,
13 };
14
15 char GetOperation()
16 {
17    char operation = 0;
18    PrintLn("Chose an operation to perform: +, -. q to quit.");
19    do
20    {
21       char input[1024];
22       gets(input);
23       switch(input[0])
24       {
25          case '+': case '-': case 'q':
26             operation = input[0];
27             break;
28          default:
29             PrintLn("Invalid Operation");
30       }
31    } while(!operation);
32    return operation;
33 }
34
35 KnownColor GetOperand()
36 {
37    KnownColor operand;
38    char input[1024];
39    gets(input);
40    while(!operand.OnGetDataFromString(input))
41    {
42       Print("Please enter a known color (black, red, green, blue, yellow, magenta, cyan or white)");
43       gets(input);
44    }
45    return operand;
46 }
47
48 KnownColor ComputeOperation(char operation, KnownColor operand1, KnownColor operand2)
49 {
50    switch(operation)
51    {
52       case '+': return operand1 + operand2;
53       case '-': return operand1 - operand2;
54    }
55 }
56
57 class Lab5ColorsApp : Application
58 {
59    void Main()
60    {
61       while(true)
62       {
63          KnownColor operand1, operand2;
64          char operation = GetOperation();
65          if(operation == 'q') break;
66
67          PrintLn("Enter the first operand:");
68          operand1 = GetOperand();
69          PrintLn("Enter the second operand:");
70          operand2 = GetOperand();
71          {
72             KnownColor result = ComputeOperation(operation, operand1, operand2);
73             PrintLn(operand1, " ", operation, " ", operand2, " = ", result);
74          }
75       }
76       system("pause");
77    }
78 }