Code Example
#include <iostream>
#include <string>
using namespace std;
int main() {
string name;
int first;
int second;
cout << "Enter name: ";
cin >> name;
cout << "Enter two numbers: ";
cin >> first >> second;
cout << name << ", sum = " << first + second << endl;
return 0;
}
Expected Output
Enter name: Mayur
Enter two numbers: 7 8
Mayur, sum = 15
Practice Steps
- Open the C++ compiler and paste the code.
- Run it and enter a name plus two numbers.
- Move the addition logic into a function for extra practice.