Created
September 25, 2017 15:08
-
-
Save mentix02/209111c0dddd413b4a94f03725f6b77a to your computer and use it in GitHub Desktop.
C++ code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AREA FINDER | |
#include <iostream.h> | |
#include <conio.h> | |
void main() | |
{ | |
clrscr(); | |
int userOption; | |
float area; | |
cout << "AREA FINDER\n"; | |
cout << "1. Square\n2. Circle\n3. Rectangle\n"; | |
cout << "Enter option : "; | |
cin >> userOption; | |
switch (userOption) | |
{ | |
case 1: | |
float side; | |
cout << "Enter length of side : "; | |
cin >> side; | |
area = side * side; | |
cout << "Area is " << area << " units\n"; | |
break; | |
case 2: | |
float radius; | |
cout << "Enter radius : "; | |
cin >> radius; | |
area = 3.14 * radius * radius; | |
cout << "Area is " << area << " units\n"; | |
break; | |
case 3: | |
float length, width; | |
cout << "Enter length : "; | |
cin >> length; | |
cout << "Enter width : "; | |
cin >> width; | |
area = length * width; | |
cout << "Area is " << area << " units\n"; | |
break; | |
default: | |
cout << "WRONG INPUT. ERROR. QUITTING!\n"; | |
} | |
cout << "\n\nEnter any key to exit.\n"; | |
getch(); | |
} | |
// GREATEST NUMBER IN 3 | |
// include all header files like in the one above - | |
void main() | |
{ | |
clrscr(); | |
float a, b, c; | |
cout << "Enter value for a : "; | |
cin >> a; | |
cout << "Enter value for b : "; | |
cin >> b; | |
cout << "Enter value for c : "; | |
cin >> c; | |
if (a > b && a > c) | |
{ | |
cout << a << " is the greatest!\n"; | |
} | |
else if (b > a && b > c) | |
{ | |
cout << b << " is the greatest\n"; | |
} | |
else | |
{ | |
cout << c << " is the greates!\n"; | |
} | |
cout << "Press any key to exit."; | |
getch(); | |
} | |
// CONDITIONAL OPERATORS | |
// INCLUDE ALL HEADER FILES LIKE ONE ABOCE | |
void main() | |
{ | |
clrscr(); | |
int a, b; | |
cout << "Enter value for a : "; | |
cin >> a; | |
cout << "Enter value for b : "; | |
cin >> b; | |
// CHECK | |
if (a > b || a == b) | |
{ | |
cout << "Either a is greater than b or equal to it.\n"; | |
} | |
else if ( a > 0 && b > 0) | |
{ | |
cout << "Both the values are positive\n"; | |
} | |
else if ( a < 0 && b > 0 || a > 0 && b < 0) | |
{ | |
cout << "One of the values is positive and the other is negative!\n"; | |
} | |
else | |
{ | |
cout << "None of the conditions were met!\n"; | |
} | |
cout << "Press any key to exit."; | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment