From 6d693a7f503ebf4c431e8220a620873513312a54 Mon Sep 17 00:00:00 2001 From: left_adjoint Date: Wed, 10 Jan 2024 16:46:54 -0800 Subject: [PATCH] added files from lecture 2 --- averager.cpp | 20 ++++++++++++++++++++ choosing.cpp | 18 ++++++++++++++++++ hello.cpp | 8 ++++++++ inverter.cpp | 18 ++++++++++++++++++ looping.cpp | 12 ++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 averager.cpp create mode 100644 choosing.cpp create mode 100644 hello.cpp create mode 100644 inverter.cpp create mode 100644 looping.cpp diff --git a/averager.cpp b/averager.cpp new file mode 100644 index 0000000..14dc3db --- /dev/null +++ b/averager.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; + +// 1. read in two numbers +// 2. calculate the average (n1 + n2)/2 +// 3. print out the average + +int main(){ + float num1 = 0; + float num2 = 0; + + cout << "Enter a number: "; + cin >> num1; + cout << "Enter another number: "; + cin >> num2; + + cout << "The average is " << (num1 + num2)/2 << endl; + + return 0; +} \ No newline at end of file diff --git a/choosing.cpp b/choosing.cpp new file mode 100644 index 0000000..703af73 --- /dev/null +++ b/choosing.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +int main(){ + // bool has two values: true and false + bool isItTrue = (false == 0); + cout << isItTrue << endl; + + //cout << "Is it...?(true/false): "; + //cin >> isItTrue; + + if(isItTrue){ + cout << "It is!" << endl; + } + else{ + cout << "It ain't" << endl; + } +} \ No newline at end of file diff --git a/hello.cpp b/hello.cpp new file mode 100644 index 0000000..6875b90 --- /dev/null +++ b/hello.cpp @@ -0,0 +1,8 @@ +#include +using namespace std; + +int main(){ + cout << "Hello world" << endl; + + return 0; +} \ No newline at end of file diff --git a/inverter.cpp b/inverter.cpp new file mode 100644 index 0000000..6cc3abd --- /dev/null +++ b/inverter.cpp @@ -0,0 +1,18 @@ +#include +using namespace std; + +// program should read in a number and return 1/the number + +int main(){ + float ourNum; + cout << "Enter a number to invert: "; + cin >> ourNum; + if( ourNum != 0){ + cout << "The inverse of that number is: " + << 1/ourNum << endl; + } + else { + cout << "You can't invert 0, you jerk" << endl; + } + return 0; +} \ No newline at end of file diff --git a/looping.cpp b/looping.cpp new file mode 100644 index 0000000..1512476 --- /dev/null +++ b/looping.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; + +int main(){ + int ourNum = 0; + + while(ourNum < 10){ + cout << "Enter a number: "; + cin >> ourNum; + } + cout << "Congrats you entered something >= 10" << endl; +} \ No newline at end of file