Output problem

Hi, I have the following code:
#include <iostream>

using namespace std;

int main()
{
int num;
string out;
do{
cin>>num;
if(num%2==0 && num!=0){
out+="e";
}
else if(num !=0){
out+="u";
}
}while(num);

return 0;
}
This code should cout LEFT if the input is uneven and right if it is. The string should be the output. If you cout that string, you will have something such as ueeuuueeeue. I want to cout uneven or even in order to the letter (if it is e or u). So eue turns into:
EVEN
UNEVEN
EVEN
yabi_something_or_other wrote:
I want to cout uneven or even in order to the letter (if it is e or u). So eue turns into:
EVEN
UNEVEN
EVEN



1
2
3
4
5
6
7
8
#include <iostream>
#include <string>

int main()
{
   std::string ugly{ "eue" };
   for ( char c : ugly ) std::cout << ( c == 'e' ? "EVEN" : "UNEVEN" ) << '\n';
}
EVEN
UNEVEN
EVEN
Last edited on
I have problems running your code, lastchance. Does it not result as an error for you too?
yabi wrote:
I have problems running your code, lastchance. Does it not result as an error for you too?


No.

You probably need to tell your compiler to use C++11 (at least) to use that range-based loop. You can also run it in cpp.sh (hit the little gear-wheel icon to top-right of a runnable code sample).
any reason for all the convolutedness? What do you actually need? you can do this

out+="EVEN\n"; //same for uneven which is normally called 'ODD'..
and print out directly at the end. Why do you need the ueeeue strings?

I ask because your previous question, this looks like a piece of that question, and if so, it appears you are going out of your way to do as much extra code and cpu work as possible.
Last edited on
Ok, thanks lastchance
Topic archived. No new replies allowed.