You are on page 1of 5

Variable

char is for single character


string is for plain text
int/integer is for whole number (50)
double is for decimal number (1.23)
bool is for true or false
\n is newline
return is for ending a function
; = ender in sentence

Example

#include <iostream>

using namespace std;

int main()
{
string characterName = "Marc";
int character Age;
character Age = 19;
cout << "There once was a man named " << characterName << endl;
cout << "He was " << characterAge << "years old" << endl;

string characterName = "James";

cout << "He liked the name " << characterName << endl;
cout << "But did not like being " << characterAge << endl;

return 0;
}

Datatype

using namespace std;

int main ()

char grade = 'A';


string phrase = "Marc Academy";
int age = 19;
double gpa = 2.5
bool isMale = true;

return 0;
}

#include <iostream>

using namespace std;

int main ()
{
string phrase = "Marc Gwapo";
0123 45678
string phrasesub;
phrasesub = phrase.substr(4, 3);
cout << phrase [1];
cout << phrase.length();
cout << phrase.find(Gwapo);
cout << phrase.substr(4, 3);
cout << phrase;
cout << "Marc\n Academy" << endl;

return 0;
}

#include <iostream>

using namespace std;

int main ()
{

int wnum = 5;
double dnum = 5.5;

wnum+ = 80;

cout << 10 / 3.0;


cout << 10 / 3;

return 0;
}

Function
basic math function
% is remainder 2%5 is 1
squareroot = sqrt
to the power = pow
round = rounder
ceil = round up
floor = round down
fmax = greater than less than
fmin = less than greater than
#include <iostream>
#Include <cmath>
using namespace std;

int main ()
{

cout << sqrt(36);


cout << pow(3, 5);
cout << round(4.6);
cout << ceil(4.1);
cout << floor(4.8);
cout << fmax(3,10);
cout << fmin(3,10);

retunr 0;
}

Getting User Input


cout <<
cin >>
#include <iostream>
#include <cmath>
using namespace std;

int main ()
{

int age;
cout << "Enter your age: ";
cin >> age

cout << "You are " << age << " years old";

string name;
cout << "Enter your name: ";
getline (cin, name);

cout << "Hello " << name;

return 0;
}

Build a Calculator
#include <iostream>
#include <cmath>
using namespace std;

int main ()
{
int num1, num2;
cout << "Enter first number: ";
cin >> num1;

cout << "Enter second number: ";


cin >> num2;

cout << num1 + num2;


---------------------------------------------
double num1, num2;
cout << "Enter first number: ";
cin >> num1;

cout << "Enter second number: ";


cin >> num2;

cout << num1 + num2;

return 0;
}

Building a Madlibs game

#include <iostream>
#include <cmath>
using namespace std;

int main ()
{

string color, pluralNoun, celebrity;

cout << "enter a color: ";


getline (cin, color);
cout << "enter a plural noun: ";
getline (cin, pluralNoun);
cout << "enter a celebrity: ";
getline (cin, celebrity);

cout << "Roses are "<< color << endl;


cout << pluralNoun << " are blue" << endl;
cout << " I love " << celebrity << endl;

return 0;
}

Arrays
#include <iostream>
#include <cmath>
using namespace std;

int main ()
{

int luckyNUms [20]

luckyNums[15] = 100
luckNums [18] = 125

cout << luckyNums [18];

return 0;
}

Functions
void no return statement
#include <iostream>
#include <cmath>
using namespace std;

void sayHi(string name, int age) {


cout << "Hello " << name << " you are " << age << endl;

int main ()
{

sayHi ("Perges", 18) ;


sayHi ("Marc", 19) ;
sayHi ("James", 20) ;

return 0;
}

Return Statement
Functions
#include <iostream>
#include <cmath>
using namespace std;

double cube(double num) {


double result = num * num * num;
return result;
}

int main ()
{

double answer = cube (5.0);


cout << answer;

return 0;
}

if statement
&&
|| is or
! is negation operator
#include <iostream>
#include <cmath>
using namespace std;

int main()
{

bool isMale = true;


bool isTall = true;
if(isMale && isTall) {
cout << "You are a tall male";
} else if (isMale && !isTall){
cout << "You are a short male";
} else if (!isMale && isTall){
cout << "You are not a male but tall";
} else {
cout << "You are not tall and your not a male";
}

return 0;

More if statement
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
https://www.youtube.com/watch?v=vLnPwxZdW4Y 1:47:00

You might also like