CS 102
Notes for Thursday 3 February (stub)
- Meeting 6
- Assignment 3 due
- read §4.3–4.4
Nested conditional statements, the if/else
chain and switch
.
Sample program demonstrating comparison operators:
#include <stdio.h> int main() { int x = 6; int y = 7; printf("%d\n", x != y); printf("%d\n", y>x); printf("%d\n", y<7); printf("%d\n", y<=7); printf("%d\n", y-1<7); return 0; }
Sample program demonstrating a conditional statement:
#include <stdio.h> const double RICH_SALARY_CUTOFF = 250000; const double FLAT_TAX_RATE = 0.12; int main() { double salary, tax; printf("Enter salary: "); scanf("%lf", &salary); if( salary > RICH_SALARY_CUTOFF ) { printf("You are RICH!\n"); } tax = salary * FLAT_TAX_RATE; printf("Your tax is $%.2lf\n", tax); return 0; }