## C++ Math – Your Fav Topic

C++ Math Functions Examples #include <cmath> You can copy this code below. In most of these examples, we encourage users to copy the code below. // Math your fav topic #include <iostream> #include <cmath> using namespace std; int main(){ cout << "sqrt(144) = " << sqrt(144) << endl; cout << "round(2.65) = " << round(2.65) << endl; cout <<...

## C++ Array of Ints / Integers

#include <array>std::array<int,4> myGrades = {86,80,64,91}; Sample c++ Array of ints Code // std::array usage std::array<int,4> myGrades = {86,80,64,91}; #include <iostream> #include <array> using namespace std; int main(){ float sum = 0.0f; std::array<int,9> myGrades = {86,80,64,91,52,59,88,69,75}; for ( unsigned int i = 0; i < myGrades.size();i++){ std::cout <<...

## C++ Array of Strings

There are a few different ways of creating a c++ Arrays of Strings #include <array>using namespace std;std::array<string,4> family = {"brother","sister","father","mom"} // std::array usage std::array<string,3> family = {"Me","You","Them"} #include <iostream> #include <array> using namespace std; int main(){ std::array<string,6> classmates = {"George",...

## C++ Do While Syntax

Elements of a c++ do while loop do { statement(s); } while( condition ); #include <iostream> int main(){ int userCounter = 0,cnt=0; std::cout << "how many times should we loop ?\n"; std::cin >> userCounter; do { std::cout << "Counting to " << userCounter << " now in the loop for " << cnt + 1 << " times\n"; cnt++; }while( cnt < userCounter ); } So Line 13...

## C++ While loop example

As part of the flow control, we will write a c++ while loop example then examine its elements. #include <iostream> int main(){ int cnt = 0; bool isReady = true; while( isReady ){ std::cout << "Are we really in a loop\n"; ++cnt; if ( cnt > 5 ) isReady = false; } } Line 9. Does the c++ while loop example really loop only 5 times? C++ Loop Code Example So, did everything run ok? I see the...

## C++ Flow Control if else switch case syntax – steal our code

There are a number of flow control syntax constructs in C++. They are basically the same as those in C, so if you are a C programmer you can skip this section. The c++ flow control constructs involve variations of : if, if else if syntax, while(isTrue) ..., do ... while(isTrue) and my favorite ...c++ switch case syntax ...with variations of continue, break and default c++ Flow Control Code...

## C++ Booleans and flow control,

C++ Booleans are a byte sized memory space which simply holds the data variable for " is it true or is it not?". Programmers usually put the word "is" in front of the variable so that it reads more English like. So a bool is likely to be named isbeautiful or isCorrect, rather than simply beautiful which could be an int rating from 1 - 10. Adding the "is" to a variable such as "cold" does not...

## Lesson 4 – C++ Char Type, String Type

Diving into the c++ char type. This very small memory type holds enough space for 1 English type character. Below x is a single char. However, y is an array of chars. Both c and c++ have several ways of expressing an array of chars. char x = 'C';char y = {'C','h','e','r','r','y','\0'}; /* We look at the char type that holds single characters Programmer: Jane Doe Date : May 2020 */ #include...

## Lesson 3 – C++ int to Double – explicit cast

Let's discuss the c++ int to double and explicit casting. Without the casting a strange kind of math occurs -- one that might surprise your math teacher. int x=1, y=2;double z;z = double(x) / y; /* We look at the double data type it can hold #'s with decimal points Programmer: Jane Doe Cause : C++ Int to Double, explicit cast Date : May 2020 */ #include <iostream> using namespace std; int...

## Lesson 2 – C++ int variables

The int and double. There are many arcane tings' about C++ programming that we are not going to get into immediately in order to keep things simple. Those are for advanced developers. The aim is to quickly push you through so that you are programming as quickly as possible. Remember that you can copy and paste this code up at and test it immediately. The online compiler is your friend. /* We...
Top