Skip to content

Instantly share code, notes, and snippets.

@rszewczyk
Last active November 9, 2017 22:04
Show Gist options
  • Save rszewczyk/67e3fd936e687d00905451ff321ef1db to your computer and use it in GitHub Desktop.
Save rszewczyk/67e3fd936e687d00905451ff321ef1db to your computer and use it in GitHub Desktop.
CMSC 104 - Class 19 11/9/2017

Class 19 Assignment

If you haven't already done so, complete the class 18 assigment and submit it.

When you are done save circles.c to another file called circles2.c. Modify it so that the program will run a maximum of 5 calulcations - i.e. immediately after the program performs its fifth calculation it exits. It should still also exit if the user at any point chooses not to continue.

The program should inform the user if it is exiting because it's reached the maximum calculations.

Sample Input/Output

Enter radius1: 1
Enter radius2: 3
The difference in area is: 25.120000
Enter y to calculate another or any other key to exit.
y
Enter radius1: 4
Enter radius2: 6
The difference in area is: 62.800000
Enter y to calculate another or any other key to exit.
y
Enter radius1: 2
Enter radius2: 5
The difference in area is: 65.940000
Enter y to calculate another or any other key to exit.
y
Enter radius1: 9
Enter radius2: 9.5
The difference in area is: 29.045000
Enter y to calculate another or any other key to exit.
y
Enter radius1: 10
Enter radius2: 10
The difference in area is: 0.000000

Maximum calculations reached, Goodbye!

Relational and Logical Operators

Review of Relational Operators

These operators are used to compare to values, or two expressions.

< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
!= Not equal to
== Equal to

Examples:

1 < 2 // true
10 <= 7 // false
12 - 6 != 6 // false
number + 3 >= 10 // true if `number` is 7 or more

Logical Operators

Simple relational expressions like the examples above can be combined into more complex expressions using logical operators.

&& AND
|| OR
! NOT

Given two expressions A and B:

A && B is true if A and B are both true
A || B is true if at least one of A or B is true
!A is true if A is false

Examples:

1 < 2 && 4 >= 3 // true - both expressions are true
1 < 2 && 4 == 3 // false - the expressions are not both true
1 < 2 || 4 == 3 // true - at least one of the expressions is true
1 > 2 || 4 == 3 // false - neither expression is true
!(4 < 3) // true - 4 < 3 is false and the ! make it true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment