//choices.cpp #include //for cin and cout using namespace std; int main() { //Simple if [then] else //There is no "then" but there //is a then clause. int grade; cout << "Enter numerical grade:\n"; cin >> grade; if (grade>=60) cout << "PASS\n"; else cout << "FAIL\n"; //Can have an if without an else char response; cout << "Did you pass go?\n"; cin >> response; if (response=='y' || response=='Y') cout << "Collect $200.\n"; //can combine float displacement,start,finish; cout << "Enter initial and final locations:\n"; cin >> start >> finish; displacement=finish-start; if (displacement>0) cout << "Moved forward.\n"; else if (displacement<0) cout << "Moved backward.\n"; else cout << "Back where you started.\n"; //switch can only make //choices based on integer values. int action; cout << "What would you like to do?\n" << "1: Withdraw from checking\n" << "2: Withdraw from saving\n" << "3: Deposit to checking\n" << "4: Deposit to saving\n"; cin >> action; switch (action) { case 1: cout << "Here is your money from checking.\n"; break; case 2: cout << "Here is your money from savings.\n"; break; case 3: case 4: cout << "Give me your money.\n"; break; default: cout << "Not a valid choice!\n"; } //end switch //notice chars are ints char letter; cout << "Enter your letter grade:\n"; cin >> letter; switch (letter) { case 'a': case 'A': cout << "Great job! ";//no break, falls through case 'b': case 'B': case 'c': case 'C': case 'd': case 'D': cout << "You passed the course.\n"; break; case 'f': case 'F': cout << "You failed. Try it again.\n"; break; //I don't need this break, but it //is safer, in case I add more cases. } //end switch return 0; }