#include <iostream>
using namespace std;
int main()
{
cout << "Enter a number: ";
int number;
cin >> number;
int i = 0;
int number2 = number;
int number3 = number;
while(i < number)
{
for(int a = 0; a < number2; ++a)
{
cout << "*";
}
for(int b = number; b < number3; --b)
{
cout << ".";
}
--number2;
--number3;
++i;
cout <<"\n";
}
return 0;
}
for loop help O-o
this part of your code has problem
you are decrementing so it should be like
for(int b = number; b > number3; --b)
{
cout << ".";
}
:)
for(int b = number; b < number3; --b) { cout << "."; }
you are decrementing so it should be like
for(int b = number; b > number3; --b)
{
cout << ".";
}
:)
for(int a = 0; a < number2; ++a)
{
cout << "*";
}
for(int b = number2; b < number3; ++b)
{
cout << ".";
}
and do not decrement number3
{
cout << "*";
}
for(int b = number2; b < number3; ++b)
{
cout << ".";
}
and do not decrement number3
Quote:Original post by ahmedkl
this part of your code has problemfor(int b = number; b < number3; --b) { cout << "."; }
you are decrementing so it should be like
for(int b = number; b > number3; --b)
{
cout << ".";
}
:)
ahh that was it. Just had the wrong symbol in there. ;)
Thx all.
Hint: you can do this without the "number2" and "number3" variables. The value of "number" doesn't change during the algorithm, so you should be able to make all your loops work from the value of "number" and "i".
Also, why did you make your outer loop a "while" loop, when it has the same (init; condition; step) sequence as your inner loops?
Also, why did you make your outer loop a "while" loop, when it has the same (init; condition; step) sequence as your inner loops?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement