I need to write a program that asks for an integer and a character and prints out that many characters with only 10 per column. I can't get mine to work.
int main ()
{
int number;
int line;
char character;
cout << "please enter a positive integer" << endl;
cin >> number;
cout << "please enter a character" << endl;
cin >> character;
if (number > 0)
for ( int line=0; line< number; line++)
{ cout << character << endl;
for (int number=0; number < 9; number++)
{
cout << character;
So I`ve fixed most of the problems I can see but now the only thing is, is that it stops at printing only 10 characters. Thank you for your help
int main ()
{
int number;
int line;
char character;
cout << "please enter a positive integer" << endl;
cin >> number;
cout << "please enter a character" << endl;
cin >> character;
if (number > 0)
for ( int line=0; line > 10; line++)
{ cout << character;
number = number - 10;
}
for (int number; number < 10; number++)
{
cout << character;
}
It's because for (int number; number < 10; number++)
If you examine it, it only prints 10 times.
I suggest a for() loop - for(int i = 0; i < number; i++)
Print character. If i is divisible by 9 without remainder (hint: modulo) because that's the 10th character, print a newline.
I'm not sure how to do the modulo correctly. I've got it printing the right amount of characters but now it doesn't cut off at only ten per line.
int number;
int line;
char character;
cout << "please enter a positive integer" << endl;
cin >> number;
cout << "please enter a character" << endl;
cin >> character;
if (number > 0)
for ( int j=0; j > character; j++)
{ cout << character << endl;
number = number - 10;
}
for (int i; i < number; i++)
{
cout << character;
if (i%9==0);
if (number > 0)
{
for (int i = 0; i < number; i++)
{
std::cout << character;
if (i % 9 == 0) // if its the tenth character
std::cout << "\n"; // newline
}
}
Also I don't know if it's just me... but I see over 5 threads on this same topic in this forum...