-3
#include <iostream> 
#include <stdio.h>
#include <string>

using namespace std;

int x, y;
int main()

{

    cout << "Please give me a number:";
    int x = (cin, x);

    cout << "Please give me another number:";
    int y = (cin, y);

    cout << "The sum of " << x;
    cout << "and " << y;
    cout << "is " << x+y;
}

Can anyone tell me why(as simple as it is) this doesn't add? I'm not really sure how to return user input for numbers and the like. Just started learning this.

2 Answers2

3

I believe instead of this:

int x = (cin, x);

you wanted this:

cin >> x;

cin (console input) works pretty much the same way as cout (console output), which you used properly.

You may want to read about them more:

Also, you do not need to redefine x and y in main(), as they are global variables.

Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49
1

Correct code is :

#include <iostream> // for cin,cout we use iostream
#include <stdio.h> // you don't need this header file in this program
#include <string> // also you don't need this header

 using namespace std;

 int main()
 {
   int x,y;
   cout<<"Please give me a number : ";
   cin>>x;
   cout<<"Please give me another number : ";
   cin>>y;
   cout<<"The sum of "<<x<<" and "<< y<<" is "<<x+y;
   return 0;
 }

Read Basic_Syntax

udit043
  • 1,610
  • 3
  • 22
  • 40