Skip to content

Commit f5daa93

Browse files
committed
add 20 to 30 for c++
fix for my whitespace from before- sorry
1 parent 60e9040 commit f5daa93

18 files changed

Lines changed: 261 additions & 69 deletions

C++/15_cppBeginners.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ using namespace std;
44

55
int main()
66
{
7-
Burrito bo; // create an object
8-
return 0;
7+
Burrito bo; // create an object
8+
return 0;
99
}

C++/16_cppBeginners.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ using namespace std;
33

44
int main()
55
{
6-
int x = 10;
7-
int y = 43;
6+
int x = 10;
7+
int y = 43;
88

9-
if (x == 10){ // 10 equals 10 - true
10-
cout << "omg i am preggy" << endl;
11-
}
9+
if (x == 10){ // 10 equals 10 - true
10+
cout << "omg i am preggy" << endl;
11+
}
1212

13-
if (x != 87){ // 10 is not equal to 87 - true
14-
cout << "omg i am preggy" << endl;
15-
}
13+
if (x != 87){ // 10 is not equal to 87 - true
14+
cout << "omg i am preggy" << endl;
15+
}
1616

17-
if (x < 87){ // is 10 less than 87? - true
18-
cout << "omg i am preggy" << endl;
19-
}
17+
if (x < 87){ // is 10 less than 87? - true
18+
cout << "omg i am preggy" << endl;
19+
}
2020

21-
if (x > 87){ // is 10 greater than 87? - false
22-
cout << "omg i am preggy" << endl;
23-
}
21+
if (x > 87){ // is 10 greater than 87? - false
22+
cout << "omg i am preggy" << endl;
23+
}
2424

25-
if (x <= 10){ // is 10 less than or equal to 10? - true
26-
cout << "omg i am preggy" << endl;
27-
}
25+
if (x <= 10){ // is 10 less than or equal to 10? - true
26+
cout << "omg i am preggy" << endl;
27+
}
2828

29-
if (x >= y){ // is 10 greater than or equal to 43 - false
30-
cout << "omg i am preggy" << endl;
31-
}
29+
if (x >= y){ // is 10 greater than or equal to 43 - false
30+
cout << "omg i am preggy" << endl;
31+
}
3232

33-
return 0;
33+
return 0;
3434
}

C++/17_cppBeginners.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ using namespace std;
33

44
int main()
55
{
6-
int age = 178;
6+
int age = 178;
77

8-
if(age>60){
9-
cout << "wow you are old" << endl; // runs when the if statement is true
8+
if(age>60){
9+
cout << "wow you are old" << endl; // runs when the if statement is true
1010

11-
if (age>100){ // a nested if statement
12-
cout << "why are you stil alive?" << endl; // this statement and the above statement runs when age > 100 is true.
13-
} // so you get "wow you are old" and "why are you stil alive?" displayed on the screen.
11+
if (age>100){ // a nested if statement
12+
cout << "why are you stil alive?" << endl; // this statement and the above statement runs when age > 100 is true.
13+
} // so you get "wow you are old" and "why are you stil alive?" displayed on the screen.
1414

15-
}else{
16-
cout << "you are young, get a job" << endl; // runs when the if statement is false
17-
}
15+
}else{
16+
cout << "you are young, get a job" << endl; // runs when the if statement is false
17+
}
1818

19-
return 0;
19+
return 0;
2020
}

C++/18_cppBeginners.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ using namespace std;
33

44
int main()
55
{
6-
int bacon = 1; // start point
6+
int bacon = 1; // start point
77

8-
while(bacon <= 5){ // test to end the loop
9-
cout << "bacon is " << bacon << endl;
10-
bacon = bacon + 1; // number to increment by
11-
// HINT - there is a shorthand version: 'bacon = bacon + 1' is the same as 'bacon++';
12-
}
8+
while(bacon <= 5){ // test to end the loop
9+
cout << "bacon is " << bacon << endl;
10+
bacon = bacon + 1; // number to increment by
11+
// HINT - there is a shorthand version: 'bacon = bacon + 1' is the same as 'bacon++';
12+
}
1313

14-
return 0;
14+
return 0;
1515
}

C++/19_cppBeginners.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ using namespace std;
33

44
int main()
55
{
6-
int x = 1; // loop start point
7-
int number; // store the number the user enters
8-
int total = 0; // store the sum of the numbers
6+
int x = 1; // loop start point
7+
int number; // store the number the user enters
8+
int total = 0; // store the sum of the numbers
99

10-
while (x <= 5){
11-
cin >> number; // ask the user for a number and store it in the number variable
12-
total = total + number; // add the number to the total. HINT - the shorthand version is: total += number;
13-
x++; // is the same as: x = x + 1;
14-
}
10+
while (x <= 5){
11+
cin >> number; // ask the user for a number and store it in the number variable
12+
total = total + number; // add the number to the total. HINT - the shorthand version is: total += number;
13+
x++; // is the same as: x = x + 1;
14+
}
1515

16-
cout << "Your total is " << total << endl;
16+
cout << "Your total is " << total << endl;
1717

18-
return 0;
18+
return 0;
1919
}

C++/20_cppBeginners.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ using namespace std;
33

44
int main()
55
{
6-
int age;
7-
int ageTotal = 0;
8-
int numberOfPeopleEntered = 0;
6+
int age;
7+
int ageTotal = 0;
8+
int numberOfPeopleEntered = 0;
99

10-
cout << "Enter first persons age or -1 to quit" << endl;
11-
cin >> age;
10+
cout << "Enter first persons age or -1 to quit" << endl;
11+
cin >> age;
1212

13-
while(age != -1){
14-
ageTotal = ageTotal + age; // or shorthand: ageTotal += age;
15-
numberOfPeopleEntered++;
13+
while(age != -1){
14+
ageTotal = ageTotal + age; // or shorthand: ageTotal += age;
15+
numberOfPeopleEntered++;
1616

17-
cout << "Enter next persons age or -1 to quit" << endl;
18-
cin >> age;
19-
}
17+
cout << "Enter next persons age or -1 to quit" << endl;
18+
cin >> age;
19+
}
2020

21-
cout << "Number of peoople eneted: " << numberOfPeopleEntered << endl;
22-
cout << "Average age: " << ageTotal/numberOfPeopleEntered;
21+
cout << "Number of peoople eneted: " << numberOfPeopleEntered << endl;
22+
cout << "Average age: " << ageTotal/numberOfPeopleEntered;
2323

24-
return 0;
24+
return 0;
2525
}

C++/21_cppBeginners.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
7+
int a = 10, b = 10, c = 10, d = 10, e = 10, x;
8+
9+
a += 5; // is the same as a = a + 5;
10+
cout << a << endl;
11+
12+
b -= 5; // is the same as b = b - 5;
13+
cout << b << endl;
14+
15+
c *= 5; // is the same as c = c * 5;
16+
cout << c << endl;
17+
18+
d /= 5; // is the same as d = d / 5;
19+
cout << d << endl;
20+
21+
e %= 3; // is the same as e = e % 3; Modulus Operator (%) - divides the values and than returns the remainder - 10 % 3 = 1
22+
cout << e << endl;
23+
24+
25+
// increment operators
26+
x = 20;
27+
cout << x++ << endl; // first it prints the value than it will increment x - 20
28+
cout << x << endl; // 21
29+
30+
x = 20;
31+
cout << ++x << endl; // increments first and than it will print the value of x - 21
32+
cout << x << endl; // 21
33+
34+
x = 20;
35+
cout << x-- << endl; // first it prints the value than it will decrement x - 20
36+
cout << x << endl; // 19
37+
38+
x = 20;
39+
cout << --x << endl; // decrement first and than it will print the value of x - 19
40+
cout << x << endl; // 19
41+
42+
}

C++/22_cppBeginners.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
7+
for (int x = 1; x < 10; x++){ // initialisation; loop continuation condition; increment
8+
cout << x << endl;
9+
}
10+
11+
for (int y = 5; y < 50; y+=5){
12+
cout << y << endl;
13+
}
14+
15+
}

C++/23_cppBeginners.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
#include <cmath> // include cmath library
3+
using namespace std;
4+
5+
int main()
6+
{
7+
8+
float a; // amount
9+
float p = 10000; // principal amount - start amount
10+
float r = .03; // interest rate
11+
12+
for (int day = 1; day <=30; day++){
13+
a = p * pow(1+r, day);
14+
cout << day << " ----- " << a << endl;
15+
}
16+
}

C++/24_cppBeginners.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
7+
int x = 99;
8+
9+
do{ // will run at least one time
10+
cout <<x<<endl;
11+
x++;
12+
}while(x<10); // test is false
13+
14+
}

0 commit comments

Comments
 (0)