top of page
How to do arithmetic operations

We will now begin by explaining the first two projects that we will develop and will use everything we learned in the previous lesson
(variables, cout) we will add the arithmetic operations (+ - */) to them

The first project: calculating the age

#include<iostream>// We start by placing the libraries
using namespace std;// We start by placing the libraries
int main(){// main function
int CurrentYear = 2023;// We define a variable for the current year
int YearOfBirth=1999;// We define a variable for the year you were born
int age = CurrentYear-YearOfBirth;
// we mark- Let's subtract the current year from the year you were born to calculate the age
cout<<"your age is "<<age;
// Put "your age is" in double quotation marks because it's text only and then put >> So we tell the program that  text  age to be printed is private to the variable
return 0;// Set a flag that says we're done
}

output
your age is 24
https://onlinegdb.com/2eciH5xC8

Second project: fat arithmetic operations

#include<iostream>// We start by placing the libraries
using namespace std;// We start by placing the libraries
int main(){// main function
int chicken=33;// We define a variable for the number of chickens
intmeat=48;// We define a variable for the number of meat
int multiplication=meat*chicken;// multiply
int division = meat/chicken;//we swear
int differential = meat-chicken;// subtract
int summation = meat+chicken;// we collect
cout<<"The multiplication is " <<multiplication<<endl<<"The division is "<<division<<endl<<"The differential is "<<differential<< ;endl<<"The summation is "<<summation<<endl;
// We print the results of the calculations
return 0;
}

output
The multiplication is 1584
The division is 1
The differential is 15
The summation is 81
https://onlinegdb.com/T1h0KyLl

bottom of page