vote1

can someone help me to do the
program that reads age of a person and tells wether the person can vote or not. Ages should be written in a text file and output whoud be displayed in the console. Refer to the text file below. Your program should define a function with the following prototype.

void vote(int age);
27
18
9
0
5
19
17
16
-1
Sample Output:

Person 1 can vote.
Person 2 can vote.
Person 3 cannot vote.
Person 4 cannot vote.
Person 5 cannot vote.
Person 6 can vote.
Person 7 cannot vote.
Person 8 cannot vote

Input File: age.txt
A negative value serves as a dummy input. The program stops reading as soon as a negative value is read. However, it will not be recognized as an age.


please... idont know how?
You'll need to do more than that. Try doing some work yourself first, then ask us about what you've tried.
closed account (4Gb4jE8b)
Do you have any code that you've worked on?
I worked on a very similar problem in a Logic class with flowcharts. I haven't done this with code yet though. I'm not sure what to tell you without spoiling some of the assignment. =\

Just write down your Input, Processing, and Output, and what needs to be done.
Last edited on
You might want to open up that txt file for read via <fstream>, read it line by line, then insert each line into your function to check IF the number is what you desire, then simply create outputs accordingly.
only this code:
top=-1
size=10

Function isFull()

if(top==size-1)
return true;
else
return false;


Function isEmpty()

if(top==-1)
return true;
else
return false;



Function push()

if(not full)
{
top++;
stack[top]=x;
display the element at the top of
stack (the recently added
element)
}
else
the stack is full



Function pop()


if(not empty)
{
delValue=stack[top];
top--;
display delValue, the deleted
element
}
else
The stack is empty



Function top()

void top()
{
if(top==-1)
Stack is empty
else
Display value of stack in index top
}



i dont know how to complete the code,
i really try but... it not work...
Last edited on
Topic archived. No new replies allowed.