hi im ismael balana for Phillipines....need your help....

my instructor in C++ prog-1 gave an asssignment but i cant finish...im too confusing i dont konw how to execute this..

here my code:


#include <iostream.h>

int main()
{
int age=0;
char citizen=(char)y || n;
int citizen = 5;
char citizen = reinterpret_cast<char>(y);


cout<<"Enter your age";
cin>> age&&citizen;
if (age>=18 || age<18)
{
cout<<"Are you filipino citizen?(y/n):"<<endl;
cin>> citizen;
{
if (citizen=="y")
{
cout<<"You are eligible to vote"<<endl;
}
else
{
cout<<"You are not eligible to vote"<<endl;
if else
{

cout<<"Are you filipino citizen?(y/n):"<<endl;
cin>> citizen;
{

if (citizen==y)
{
cout<<"You are eligible to vote"<<endl;
}
else
{
cout<<"You are not eligible to vote"<<endl;

}
}
}








return 0;
}
}
}

but its has many errors;;;;like this;
--------------------Configuration: case study voters - Win32 Debug--------------------
Compiling...
case study voters.cpp
\\PC9\ISMAEL BALANA\case study voters.cpp(6) : error C2065: 'y' : undeclared identifier
\\PC9\ISMAEL BALANA\case study voters.cpp(6) : error C2065: 'n' : undeclared identifier
\\PC9\ISMAEL BALANA\case study voters.cpp(7) : error C2371: 'citizen' : redefinition; different basic types
\\PC9\ISMAEL BALANA\case study voters.cpp(6) : see declaration of 'citizen'
\\PC9\ISMAEL BALANA\case study voters.cpp(8) : error C2374: 'citizen' : redefinition; multiple initialization
\\PC9\ISMAEL BALANA\case study voters.cpp(6) : see declaration of 'citizen'
\\PC9\ISMAEL BALANA\case study voters.cpp(8) : error C2440: 'reinterpret_cast' : cannot convert from 'int' to 'char'
Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast
\\PC9\ISMAEL BALANA\case study voters.cpp(18) : error C2446: '==' : no conversion from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
\\PC9\ISMAEL BALANA\case study voters.cpp(18) : error C2040: '==' : 'int' differs in levels of indirection from 'char [2]'
\\PC9\ISMAEL BALANA\case study voters.cpp(39) : error C2143: syntax error : missing ';' before '}'
\\PC9\ISMAEL BALANA\case study voters.cpp(39) : error C2143: syntax error : missing ';' before '}'
\\PC9\ISMAEL BALANA\case study voters.cpp(39) : error C2143: syntax error : missing ';' before '}'
\\PC9\ISMAEL BALANA\case study voters.cpp(40) : error C2143: syntax error : missing ';' before '}'
\\PC9\ISMAEL BALANA\case study voters.cpp(40) : error C2143: syntax error : missing ';' before '}'
\\PC9\ISMAEL BALANA\case study voters.cpp(41) : error C2143: syntax error : missing ';' before '}'
\\PC9\ISMAEL BALANA\case study voters.cpp(41) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.

case study voters.obj - 14 error(s), 0 warning(s)




i dont konw what to do...

can anyone help me plss........




this is my instructor want to execute;
___________________________________________

Enter your age: 18
Are you Filipino citizen?(y/n || Y/N); Y

You are eligible to vote

___________________________________________


Enter your age: 17
Are you Filipino citizen?(y/n || Y/N); Y

You are not eligible to vote
___________________________________________

thank you all......in advance...

Last edited on
I am fairly new to c++ as well and currently in class but i can see a few problems with your program just glancing at it. and how i would fix it.

Fist off your not declaring your constant chars correctly. If you want citizen to = yes then use.

const char yes = 'y';
const char YES = 'Y';
also when you need to check the value you can use

if (citizen == yes || citizen == YES)


if you explained your program a bit more I could probally help more.
If this were my project, I would do it something like this:

I am assuming that even if a person is a citizen that they are not eligable to vote if they are under 18, and that only those 18 and over that are also citizens are eligable to vote with this.

#include <iostream.h>

int main()
{
int age=0; // initializes age to 0 of an int number type
char citizen; // declare citizen to be char so it can accept a y or n answer


cout<<"Enter your age"; // asks user to enter age
cin>> age; // allows cuser to enter age
cout << endl; // ends the line so that your next cout goes to the next line


if (age >= 18) // says if user is 18 ask if they are a citizen
{
cout<<"Are you filipino citizen?(y/n):"<<endl;
cin>> citizen;

if (citizen=="y") //says if they are 18 and
//answer yes they are eligable.
{
cout<<"You are eligible to vote"<<endl;
}
else // if they are 18 but answer n then they are not eligable
{
cout<<"You are not eligible to vote"<<endl;
}
else // says if they are not 18 then ask if they are a citizen but tell them //they are not eligable anyway
{
cout<<"Are you filipino citizen?(y/n):"<<endl;
cin>> citizen;
cout<<"You are not eligible to vote"<<endl;
}


return 0;
}
can you use code tags please? its a little hard to understand....
Last edited on
Topic archived. No new replies allowed.