I am attempting a Hacker Rank problem for my Programming II class. I can either get the program to print the correct values but out of order, or it prints out the wrong values in the right order
I've tried nesting the loops inside one another in different ways to change the order, or to keep the first input variable value so it can be read by the second loop. So far I haven't gotten the desired result.
int main()
{
int n;
for(int k = 0; k < 2; ++k)
{
cin >> n;
if(n == 1)
{
cout << "one\n";
}
else if(n == 2)
{
cout << "two\n";
}
else if(n == 3)
{
cout << "three\n";
}
else if(n == 4)
{
cout << "four\n";
}
else if(n == 5)
{
cout << "five\n";
}
else if(n == 6)
{
cout << "six\n";
}
else if(n == 7)
{
cout << "seven\n";
}
else if(n == 8)
{
cout << "eight\n";
}
else if (n >= 9)
{
cout << "nine\n";
}
}
for(int j = 0; j < 2; j++)
{
if(n % 2 == 0)
{
cout << "even\n";
}
else
{
cout << "odd\n";
}
}
return 0;
}
Correct result with 8 and 11 used
eight
nine
even
odd
My result
eight
nine
odd
odd