Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
C++ "Exprected primary-expression before >= token"?
// CODE
#include <iostream>
using namespace std;
int ageCalc (int year) {
int x = 2013;
int y;
y = x - year;
return(y);
}
int main() {
int birthYear, res;
cout << "What year were you born? ";
cin >> birthYear;
res = ageCalc(birthYear);
if (res >= 21) {
cout << "Let's grab a beer!";
}
else if (res <= 21 && >= 18) {
cout << "You can fight in the army.";
}
else if (res < 18 && >= 16) {
cout << "You can drive now!";
}
else {
cout << "You're just a kid.";
}
}
//CODE
On the lines with the &&'s it's saying that, what's happening?
2 Answers
- ?Lv 48 years agoFavorite Answer
It's just a simple syntax error, you're missing the variable name. It should be:
else if (res <= 21 && res>= 18) {
...also a couple of lines later....
else if (res < 18 && res >= 16) {
- Wertle WooLv 68 years ago
C++ is not English. You can't write code the way you would speak it in English. >= is a binary operator. >= 18 makes no sense. You need both operands, res >= 18.
Source(s): http://www.youtube.com/watch?v=ms2SMRqzMlo