is this a good practice to you ???

i just need your opinion ,does my coding are good practice ,pleaseee tell me what do you guys think,i think its missing something but i dont know where

#include<iostream>
using namespace std;
int main()
{
int age;
char c,r;

cin>>c;
cin>>r;
cin>>age;
if (c=='Y')
{if(r=='Y')
{if (age>=21)
cout<<"eligible to vote"<<endl;
else
cout<<"cant vote!"<<endl;
}
else
cout<<"cant't vote!!"<<endl;
}
else
cout<<"cant't vote!!!"<<endl;
}
Last edited on
does my coding are good practice

No.

i think its missing something but i dont know where

I agree, start by using meaningful variable names, and when posting code please use code tags.

closed account (48T7M4Gy)
@OP, jlb is right. Maybe this makes sense out of your stuff.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<iostream>

using namespace std;

int main()
{
    int age = 0;
    char citizen = 'N';
    char registered = 'N';
    
    cout << "Are you a citizen Y/N? ";
    cin >> citizen;
    
    if (citizen == 'Y')
    {
        cout << "Are you registered Y/N? ";
        cin >> registered;
        
        if(registered == 'Y')
        {
            cout << "How old are you? ";
            cin >> age;
            
            if (age >= 21)
                cout<<"eligible to vote"<<endl;
            else
                cout<<"cant vote!"<<endl;
        }
        else
            cout<<"cant't vote!!"<<endl;
    }
    else
        cout<<"cant't vote!!!"<<endl;
    
    return 0;
}
how about this one???



#include<iostream>
using namespace std;
int main()
{
int age;
char citizen,range;

cout<<"Please enter your citizen by (Y/N):";
cin>>citizen;

cout<<"Please enter your range by (Y/N):";
cin>>range;

cout<<"Please enter your age";
cin>>age;

if (citizen=='Y')
{if(range=='Y')
{if (age>=21)
cout<<"eligible to vote"<<endl;
else
cout<<"cant vote!"<<endl;
}
else
cout<<"cant't vote!!"<<endl;
}
else
cout<<"cant't vote!!!"<<endl;
}
closed account (48T7M4Gy)
What is 'range'? Home on the range perhaps?
closed account (48T7M4Gy)
BTW Please use code tags - select the text, press the <> button in toolbox on the right of this panel.

Also, you should initialize variables, eg int age = 0; etc and properly indenting your code is always a good move.

Try it by editing your latest post.

because the question saids range ,so im just followed order
closed account (48T7M4Gy)
OK. I have no idea what range is either.

Anyway, now all you need to do is look at what I posted and hopefully you got a chance to look at the one that JLBorges deleted because you can allow for upper and lower case user responses if(citizen == 'y' || citizen == 'Y') etc, and more useful answers like "You can't vote because you aren't old enough" etc

You might like to consider that the first question might be "Are you registered to vote?" and follow the logical path(s) from there.
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/220624/
THANK YOU!!!
learn to comment your code.
Topic archived. No new replies allowed.