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;
}

Recommended Answers

All 6 Replies

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... */

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.