added files from lecture 2

This commit is contained in:
left_adjoint 2024-01-10 16:46:54 -08:00
parent 34f06aedf5
commit 6d693a7f50
5 changed files with 76 additions and 0 deletions

20
averager.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <iostream>
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;
}

18
choosing.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <iostream>
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;
}
}

8
hello.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <iostream>
using namespace std;
int main(){
cout << "Hello world" << endl;
return 0;
}

18
inverter.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <iostream>
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;
}

12
looping.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <iostream>
using namespace std;
int main(){
int ourNum = 0;
while(ourNum < 10){
cout << "Enter a number: ";
cin >> ourNum;
}
cout << "Congrats you entered something >= 10" << endl;
}