Objective:

Write a C++ program that calculates the sum of two numbers entered by the user.

Task:

  1. Write a program that prompts the user to enter two numbers.
  2. The program should calculate the sum of the two numbers and display the result.

Code:

#include <iostream>
using namespace std;

int main() {
    int num1, num2, sum;

    cout << "Enter first number: ";
    cin >> num1;

    cout << "Enter second number: ";
    cin >> num2;

    sum = num1 + num2;
    cout << "The sum is: " << sum << endl;

    return 0;
}

Explanation:

This program prompts the user to enter two numbers (num1 and num2).
It calculates the sum of the numbers and stores it in the sum variable.
Finally, it outputs the result using the cout statement.

Expected Output:

Enter first number: 5
Enter second number: 8
The sum is: 13