Saturday, August 6, 2016

Addition of two numbers program


Here a,b and answer are integer variables which I declared to store the values which the user gives and store them in those variables. As the user giving numbers as inputs integer variables were needed.

Here the cin used to get inputs from the user. It is also a part of the iostream library as same as cout. cin takes data from the user and stored them in the specific variable.

As an example the first cin takes the first number which gives the user and stored it in the variable "a".

As I explained all the other codes in the previous post. I'm not going to explain all the codes again and again. I'll only explain the new codes which will in the code.

So this programs purpose is to get two numbers from the user and add them together and show the result to the user.



#include <iostream> 
#include <stdlib.h>

using namespace std;

int main(){
 system("cls");
 int a,b,answer;
 
 cout << "\t======================================\n";
 cout << "\tWelcome to the add two number program!\n";
 cout << "\t======================================\n\n\n";
 cout << "Enter the first number\t\t: ";
 cin >> a;
 cout << "\n";
 cout << "Enter the second number\t\t: ";
 cin >> b;
 
 answer = a + b;
 cout << "\n";
 cout << "The sum of the two numbers is\t: " << answer << "\n\n\n\n\n";
 
 system("pause");
}

output:


No comments:

Post a Comment