Simple Code - Stumped on an Error

Hey all. I'm new to C++ and this code I'm working on is my first "project" if you will. It's not complex at all, but I can't figure out where I'm going wrong. Every time I try to compile it I get the error: C:\Dev-Cpp\main.cpp In function `int main()': . Here's the code:

#include <iostream>

using namespace std;

int main ()
{

int a;

cout<< "Please enter a number: ";

cin>> int a;

int b;

cout<< "Please enter another number: ";

cin>> int b;

int c;

int a+int b= int c;

cout<< "The sum of the two numbers you entered is: " << int c << "\n";

return 0
}


The underlined/bolded line is where I'm getting the error. I've googled this and poked around these forums, but I haven't found a fix.

I appreciate all help and tips, thanks.
Last edited on
type variable is only used when declaring the variable. To actually use the variable you simply do variable.
For example,
1
2
int a;
std::cin >>a;
Last edited on
Wow, that seems almost to easy.

Thanks.
Also, the variable that is being assigned goes on the left on the assignment operator, so your 11th line could be:
int c = a + b;
your code should be like this. note : you should not redeclare the variables.

#include <iostream>

using namespace std;

int main ()
{

int a;

cout<< "Please enter a number: ";

cin>>a;

int b;

cout<< "Please enter another number: ";

cin>>b;

int c;

c = a+b;

cout<< "The sum of the two numbers you entered is: " << c << "\n";

system("pause");
}
Topic archived. No new replies allowed.