Input a number between 1-9, then choose 2 character, e.g: * and =.
The sample output:
Enter number: 5
Enter character: * =
*
==
***
====
*****

I had tried many times, but don't know where i was doing wrongly. Please help, thanks!:)

#include <iostream>
using namespace std;
int main()
{
int x,i,j;
char ch1, ch2;
cout<<"Please enter any 2 characters."<<endl;
cin>>ch1>>ch2;
cout<<"Please input an number."<<endl;
cout<<"(between 1-9)"<<endl;
cin>>x;
if (x>0 && x<=9)
	{
		bool isOdd;
			for (i=0; i<x; i++)
			{
				isOdd=false;
				for (i=0; i<x; i++)
				{
					if ((x%2)==1)
						isOdd=true;
				}
			}
			if (isOdd)
			{
				cout<<ch1<<endl;
				i++;
			}
			else
			{
				for (j=0; j<i; j++)
				{
					cout<<ch2<<endl;
					j++;
				}
			}
}
else
{
cout<<"Error!"<<endl;
}
return 0;
}

Edited 6 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

Having trouble making sense of your code. Please re-post using code tags.

/*this is what you'll get */ 
/* and you're more likely to get help... */

Edited 3 Years Ago by happygeek: fixed formatting

nput a number between 1-9, then choose 2 character, e.g: * and =.
The sample output:
Enter number: 5
Enter character: * =
*
==
***
====
*****

I had tried many times, but don't know where i was doing wrongly. Please help, thanks!

#include <iostream>
using namespace std;
int main()
{
int x,i,j;
char ch1, ch2;
cout<<"Please enter any 2 characters."<<endl;
cin>>ch1>>ch2;
cout<<"Please input an number."<<endl;
cout<<"(between 1-9)"<<endl;
cin>>x;
if (x>0 && x<=9)
{
bool isOdd;
for (i=0; i<x; i++)
{
isOdd=false;
for (i=0; i<x; i++)
{
if ((x%2)==1)
isOdd=true;
}
}
if (isOdd)
{
cout<<ch1<<endl;
i++;
}
else
{
for (j=0; j<i; j++)
{
cout<<ch2<<endl;
j++;
}
}
}
else
{
cout<<"Error!"<<endl;
}
return 0;
}

Hopefully someone else can help you. You should really take a hard look at your formatting, it's still completely unintelligible. Indentation exists for a reason. Have a look at almost any other thread for examples. If you can't take the time to make your code readable, no one is going to take the time to read it.

Edited 6 Years Ago by Fbody: n/a

Your code looks like this:

for (int i = 0; i < sum_number; i++)
{
cout << "I cant read this code!!\n";
}

Code should look like:

for (int i = 0; i < sum_number; i++)
{
       cout << "I can read this code!!\n";
}

Oh and one more hint, MOST compilers have an "auto fix" style feature that automatically aligns the messed up code for you. For example, in Visual Studio, if you select all your code (Ctrl + A) and press Alt + f8 it will auto format. Then you can just copy and paste your code to the forums

Edited 6 Years Ago by hag++: n/a

nput a number between 1-9, then choose 2 character, e.g: * and =.
The sample output:
Enter number: 5
Enter character: * =
*
==
***
====
*****

I had tried many times, but don't know where i was doing wrongly. Please help, thanks!

We don't know what you're doing wrongly either because only you know what you are trying to do.

This is like going to the doctor and telling him "I hurt somewhere. Fix me."

try this

for(i=0;i<no_entered ;i++)
{
           if(no_enterd%2!=0)
            {
                      for(j=0;j<no_enterd;j++)
                           cout <<"*\n";
            }
            else
            {
                      for(j=0;j<no_enterd;j++)
                           cout <<"*\n";
            }


}

hope this helps

This article has been dead for over six months. Start a new discussion instead.