Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why won't this work

+3 votes
asked May 1, 2020 by Ivana Ogunlaja (640 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, 2020 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, 2020 by Venkat (160 points)
Terminate your variable declaration with ;.
0 votes
answered May 2, 2020 by LiOS (6,420 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, 2020 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, 2020 by Afloarei Ioana (290 points)

int age;enlightened

you forgot to put " ; "!!!

commented May 10, 2020 by Afloarei Ioana (290 points)
be careful, any mistake is fatal!!
0 votes
answered May 10, 2020 by LiOS (6,420 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, 2020 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.
...