How can we write a C++ program to add two numbers?

To write a C++ program that adds two numbers we need to write the following code:

We write a line which calls a library that has functions we need:

#include

(Then we create a function that does our sum:)

int main()

(Here we read the two values we need for our sum, called x and y. These can be chosen by the user and written from the keyboard:)

{ cin>>x,y;

(In the next lines we declare a variable called S which stands for sum and then we give it the value of x+y:)

int S;

S= x+y;

(In the end, we return the value of S and close the brackets of the function)

cout<

}

Answered by Cosmin B. TBA tutor

1668 Views

See similar TBA A Level tutors

Related TBA A Level answers

All answers ▸

We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy