Why won't this work

+3 votes
asked May 1 by Ivana Ogunlaja (610 points)
#include <iostream>
using namespace std;

int main()
{
    int age
    cout << "How old are you";
    cin >> age;
    if(age>17){
        cout << "You can vote";
    }else{
        cout << "You can't vote";
    }
    return 0;
}

7 Answers

0 votes
answered May 1 by sowmya8900 (180 points)
#include <iostream>
using namespace std;

int main()
{
    int age; // You missed the semi-colon while declaring the age.
    cout << "How old are you";
    cin >> age;
    if(age>17)
    {
        cout << "You can vote";
    }
    else
    {
        cout << "You can't vote";
    }
    return 0;
}

Also, take care of the indentation while programming. Although it doesn't matter in C++ but it increases readability.
Happy coding!
0 votes
answered May 1 by Venkat (160 points)
Terminate your variable declaration with ;.
0 votes
answered May 2 by LiOS (5,280 points)
Missing ; on line 6

Working code:

#include <iostream>
using namespace std;

int main()
{
    int age;
    cout << "How old are you";
    cin >> age;
    if(age>17){
        cout << "You can vote";
    }else{
        cout << "You can't vote";
    }
    return 0;
}
0 votes
answered May 8 by FatehSingh (180 points)
You are just missing a semi-colon after the very first line of your main function which is:

int age;

Have a good one.
0 votes
answered May 10 by Afloarei (280 points)

int age;enlightened

you forgot to put " ; "!!!

commented May 10 by Afloarei (280 points)
be careful, any mistake is fatal!!
0 votes
answered May 10 by LiOS (5,280 points)
- Missing ; to terminate variable declaration on line 6

#include <iostream>
using namespace std;

int main()
{
    int age;
    cout << "How old are you";
    cin >> age;
    if(age>17){
        cout << "You can vote";
    }else{
        cout << "You can't vote";
    }
    return 0;
}
0 votes
answered May 13 by Mason Gleeson (140 points)

#include <iostream>
using namespace std;

int main()
{
    int age; //you need to put a semicolon at the end of this line
    cout << "How old are you";
    cin >> age;
    if(age>17){
        cout << "You can vote";
    }else{
        cout << "You can't vote";
    }
    return 0;
}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...