Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to output

2 Bat
3 Man
4 Bat
5 Cave
6 BatMan
8 Bat
9 Man
10 BatCave

**no 1 and 7
**i need the output of
6 and 10

**i only got

2 Bat
3 Man
4 Bat
5 Cave
6 Bat
Man
8 Bat
9 Man
10 Bat
Cave


C++
#include <iostream>
using namespace std;
int main()
{
	
	for (int n=1; n<=10; n++)
	{
		if (n == 1 || n == 7)continue;
		{
			cout<<n <<" ";

			if (n % 2 == 0)
			{
				cout<<"Bat" <<endl;
			}
			if (n % 3 == 0)
			{
				cout<<"Man" <<endl;
			}
			if (n % 5 == 0)
			{
				cout<<"Cave" <<endl;
			}
		}
	}
	system("pause");
	return 0;
}


What I have tried:

See the code above.
Posted
Updated 14-Aug-16 23:17pm
v2
Comments
OriginalGriff 15-Aug-16 4:21am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
And frankly, that makes no sense to me at all. I have no idea what you are trying to achieve, what help you need, or indeed anything else.
Use the "Improve question" widget to edit your question and provide better information.

Seems like you want to create a string to store all the combinations, before you hit endline?

(Been a while since I did C++ so you have to check the code)

C++
string myOutput = "";

if (n % 2 == 0)
{
    myOutput+="Bat";
}
if (n % 3 == 0)
{
    myOutput+="Man";
}
if (n % 5 == 0)
{
    myOutput+="Cave";
}

cout<<myOutput <<endl;
 
Share this answer
 
Change your code to:
C++
for (int n=1; n<=10; n++)
{
    if (n == 1 || n == 7)
        continue;
    cout<<n <<" ";
    
    if (n % 2 == 0)
    {
    	cout<<"Bat";
    }
    if (n % 3 == 0)
    {
    	cout<<"Man";
    }
    if (n % 5 == 0)
    {
    	cout<<"Cave";
    }
    cout << endl;
}
 
Share this answer
 
use a switch command inside your for loop:

C++
switch( i )
{
  case 0:
  case 10:
    break;

  case 1:
    break;

// all unneeded cases
  default:
     break;
}

Play around, have fun and learn coding...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900