寻找更好的方法编写这个程序C++

寻找更好的方法编写这个程序C++,c++,C++,有没有更好的方法来编写这个程序。对于加法,程序将a和b相加以得到一个和。我在寻找更好的方法 #include <iostream> using namespace std; int a = 0; int b = 0; int s = 0; int main() { cout << "Type a Number: "; cin >> a ; cout << "Type another Number:"; cin

有没有更好的方法来编写这个程序。对于加法,程序将a和b相加以得到一个和。我在寻找更好的方法

#include <iostream>
using namespace std;

int a = 0;
int b = 0;
int s = 0;

int main()
{
    cout << "Type a Number: ";
    cin >> a ;
    cout << "Type another Number:"; 
    cin >> b;
    cout << "you sum is... ";
    cout << int (s = (b + a)) << endl ;
    system ("pause"); 
}

不要使用globals如果你不必+不要使用namespaceint s=b+a不要这样写代码。在单独的一行上计算总和。您的问题最好在处提出。使用命名空间std;避免使用此选项。系统暂停;有很多方法可以绕过这个IDE限制。
 #include<iostream>
 using namespace std;
 int main()
 {
  int a=0,b=0,sum=0;
  cout<<"Type a and b"<<endl;
  cin>>a>>b;
  sum=a+b;
  cout<<sum<<endl;
  return 0;
 }