What does "[Error] expected primary-expression before 'int'" mean?

Erm... Im beginning to program today and i was just trying to make something very simple. This is probably a very simple and stupid error but help is appreciated. Also any extra tips are welcomed. Thank you guys!
#include <iostream>
// Program will ask for two numbers and add them together//

int main ()
{
std:: cout << "Hello, fellow human being. Please choose a number!/n";
int a;
std:: cout << "Choose one more, pretty please!/n";
int b;
std:: cout << "This is the sum of both your numbers:/n" >> int c >> int a + int b;
return 0;
}

LIne 10 Col 61 [Error] expected primary-expression before 'int'
Last edited on
Initialize your variables first, then code...
Once you initialize them, you don't have to do it again within that scope.
Remove the "int " from the "int c", "int a" and "int b" from your last cout statement, just use a,b, and c
cout is for writing to the screen, use cin to get the numbers you want.
learn to use code tags when posting please.


1
2
3
4
5
6
7
8
9
int main ()
{
int a,b,c=0;

std:: cout << "Hello, fellow human being. Please choose a number!/n";
std:: cout << "Choose one more, pretty please!/n";
std:: cout << "This is the sum of both your numbers:/n" << a + b;
return 0;
}



or (if you want this to function)


1
2
3
4
5
6
7
8
9
10
11
12
13
int main ()
{
int a,b,c=0;

std:: cout << "Hello, fellow human being. Please choose a number!\n";
std :: cin >> a;
std:: cout << "Choose one more, pretty please!\n";
std :: cin  >> b;
c=a+b;
std:: cout << "This is the sum of both your numbers:\n" << c;

return 0;
}

Last edited on
That's because you can't suddenly reverse input and output operators for any reason within the same line of code.

I think what you're actually wanting to do is something like:
1
2
3
4
5
6
int a, b, c;
std::cout << "stuff" << std::endl;
cin >> a;
std::cout << "stuff2" << std::endl;
cin >> b;
std::cout << "stuff3" << c << a + b << std::endl;

Last edited on
Topic archived. No new replies allowed.