I got a problem with this simple program

So I just started learning C++, and am already stuck on my first simple program I have been assigned in my class
The program is a simple program that reads an even number of characters. The algorithm then prints the first character, third character, fifth character, and so on. On a second output line, the algorithm prints the second character, fourth character, sixth character, and so on. Use two queues to store the characters.

This is my short code:

#include<iostream>
using namespace std;
int main()
{

char a= 'a';
while(a <= z)
{
if(a%2 == 0)
{
cout<<a<<"is even character"<<endl;
}
a++;
}
}

I'm slightly embarrassed having to ask help for what I am assuming is a silly error, but I have been trying to figure this out for a couple hours now and cannot figure it out. Thank you!
change

while(a <= z)

to

while(a <= 'z')

i need to do
prints the first character, third character, fifth character, and so on. On a second output line, the algorithm prints the second character, fourth character, sixth character, and so on. Use two queues to store the characters.

What you do here is that when a is divide-able by 2 (like 0, 2, 4, 6) you print it, but you want the characters that lie within those characters, in other words, not divide-able by 2. So you can change
if(a%2 == 0)
to
if(a%2 != 0)
or
if(a%2 == 1)
You can also accomplish it way easier:
1
2
3
4
5
while(a <= z)
{
    cout << a << "is an even character" << endl;
    a += 2;
}

But maybe it was not your intension to make ik easy :P.
Last edited on
And btw, if z is not an existing variable in your code, wich is not if what you showed is your whole code, then you need to create it
char z = 'z';
or change
while(a <= z)
to
while(a <= 'z')
Just like ankushnandan said.
but i know, i suppose to use two queues to store the characters. can someone help
i think your 'if' should be like this :

char ch; //just to declare the character to ch

if (ch == 'a' && ch == 'i' && ch == 'u' && ch == 'e' && ch == 'o')
{
cout << ch << " is an even chacacter" << endl;
}
else
{
cout << ch << " is an odd character" << endl;
}

use while loop as stated in comment above and insert this if.
i hope this can help. good luck. :)
Topic archived. No new replies allowed.