C++: Learning the Basics – Adding numbers

Situation #1: User types any two numbers and the program generates the sum of the two.

Here is the code:
This code is annotated for your reference. The final code (without the notes) is at the bottom of this post.

#include  #Input output stream
#include 
void main() #Entry of execution of pgm

{ #Start the code

clrscr(); #Clear the screen

int num1, num2, sum; #int referes to integer

cout<<”\n\t Enter first number: “; #Instructions for user; allows the user to insert data
cin>>num1 #Accepts values from user

cout<<”\n\t Enter second number: “; #\n\t represents new line of code
cin>>num2

sum=num1+num2 

cout<<”\n\t Sum of the two numbers: " <<sum;

}

Final code:

#include 
#include  
void main()

{   
      
clrscr();

int num1, num2, sum;

cout<<”\n\t Enter first number: “; 
cin>>num1

cout<<”\n\t Enter second number; “; 
cin>>num2

sum=num1+num2

cout<<”\n\t Sum of the two numbers: ‘ <<sum;

{

How and where can I download C++?

iOS:

Windows:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s