-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathadd_two_numbers.cpp
More file actions
41 lines (32 loc) · 1.19 KB
/
add_two_numbers.cpp
File metadata and controls
41 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*******************************************************************************
*
* Program: Add Two Numbers
*
* Description: Program to add together two numbers provided from user input and
* output the resulting sum using C++.
*
* YouTube Lesson: https://www.youtube.com/watch?v=Fk-9KCBOsp8
*
* Author: Kevin Browne @ https://portfoliocourses.com
*
*******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
// Declare 3 double variables, x and y to store the two numbers, and sum to
// store the resulting sum
double x, y, sum;
// Prompt the user to enter two numbers
cout << "Enter two numbers: ";
// Store the two numbers that the user enters into the variables x and y
cin >> x >> y;
// Sum the values of x and y and store the result into sum
sum = x + y;
// Output the resulting sum of x and y in the format x + y = sum
cout << x << " + " << y << " = " << sum << endl;
// Note that we could have used int type variables to store the numbers, but
// then the numbers could not contain decimal places as int type variables
// can only store integer values like -4,6,etc.
return 0;
}