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()
{
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!
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.
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.