c++ multiple inputs

Here is an example of how to handle multiple inputs in C++:

#include <iostream>
using namespace std;

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

    // Prompt the user to enter the first number
    cout << "Enter the first number: ";
    cin >> num1;

    // Prompt the user to enter the second number
    cout << "Enter the second number: ";
    cin >> num2;

    // Calculate the sum
    sum = num1 + num2;

    // Display the result
    cout << "The sum is: " << sum << endl;

    return 0;
}

Explanation:

  1. We include the iostream library, which allows us to use input/output operations in C++.

  2. We declare three integer variables: num1, num2, and sum. These variables will store the input values and the sum of the two numbers, respectively.

  3. The cout statement is used to prompt the user to enter the first number.

  4. The cin statement is used to read the input value from the user and store it in the num1 variable.

  5. Similarly, we prompt the user to enter the second number using another cout statement, and read the input value using a cin statement, storing it in the num2 variable.

  6. We calculate the sum of num1 and num2 and store it in the sum variable.

  7. Finally, we use a cout statement to display the result to the user.

Note: It is important to include the line using namespace std; at the beginning of the program to avoid having to specify std:: before each input/output operation.