top of page
Calculator project

Let's create a program that makes the user choose the operation and numbers he wants and the program prints the result of the operation.
If the if statement contains one line, there is no need to include curly braces {}

#include<iostream>//We start by placing the libraries
using namespace std;//We start by placing the libraries
int main(){//main function
intnumbers;
cout<<"1-summation"<<endl<<"2-differentiation"<<endl<<"3-multiplication"<<endl<<"4-division"< <endl;
cout<<"enter the number to operate";
cin>>numbers;
if (numbers>=1 &&numbers<=4){
inta,b;// if But we will only be able to call variables inside an if statement. We can define variables inside a statement 
cout<<"Please put the first number you want to operate";
cin>>
a;
cout<<"Please put the second number you want to operate";
cin>>
b;
if (numbers==1)//If the process number1 Do the following
cout<<a<<"+"<<b<<"="<<a+b<<endl;
//And do the collecting a and b Print the two numbers in 
if (numbers==2)//If the process number2 Do the following
cout<<a<<"-"<<b<<"="<<a-b<<endl;
//And do the subtraction a and b Print the two numbers in 
if (numbers==3)//If the process number3 Do the following
cout<<a<<"*"<<b<<"="<<a*b<<endl;
//And do the multiplication a and b Print the two numbers in 
if (numbers==4)//If the process number4 Do the following
cout<<a<<"/"<<b<<"="<<a/b<<endl;}
//And do the division a and b Print the two numbers in 
else{cout<<"Are you serious, I told you its from 1 to 4"<<endl;}
//
Other than that If the condition is not met, print that the number is invalid
return 0;
}

image.png
image.png
bottom of page