/* VARIABLES Variables are NOT ALLOWED until lab 7 const int x = 123; // declares x, its value can never be changed int x = 123; // creates variable x, gives it a first value x = 456; // x must already exist as variable, give it new value x = 345 * y + z * z; // so long as y and z are ints too x = x+1.0; // increases value of x by 1 */ /* I want a definite response of "yes" or "no", or to know invalid cout << "Please answer yes or no: "; const string reply = read_string(); if (reply == "yes") { const bool answer = true; const bool valid = true; } else if (reply == "no") { const bool answer = false; const bool valid = true; } else const bool valid = false; // valid and answer do not exist any more at this point */ /* // corrected version cout << "Please answer yes or no: "; const string reply = read_string(); bool answer, valid = false; if (reply == "yes") { answer = true; valid = true; } else if (reply == "no") { answer = false; valid = true; } // what if I say int x; x = x + 1; // value of x is unknown, can't rely on it being 1 */ /* // got three values x, y, z // I want m to be the smallest of them int min(int a, int b) { if (a < b) return a; return b; } const int m = min(x, min(y, z)); or using variables int min = a; if (b < min) min = b; if (c < min) min = c; */ int day_of_year(int y, int m, int d) { int result = 0; if (m > 1) result = result + 31; if (m > 2) result = result + isleapyear(y) ? 29 : 28; if (m > 3) result = result + 31; if (m > 4) result = result + 30; if (m > 5) result = result + 31; if (m > 6) result = result + 30; if (m > 7) result = result + 31; if (m > 8) result = result + 31; if (m > 9) result = result + 30; if (m > 10) result = result + 31; if (m > 11) result = result + 30; return result + d; }