When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
107 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
what have you tried so far?
#include <iostream>
using namespace std;
int main()
{
int num, i, j;
cout << "Enter a number:";
cin >> num ;
for(i = 0; i < num; i++)
{
for(j = 0; j < num; j++)
{
cout << "*";
}
}
return 0;
}```
i only have this so far
ive been thinking of how to make it go down but havent got a clue how to
;compile
Enter a number:*******************************************************************************************************************************************************************************************************************************************
🤔 don't remember how to input things anymore
anyhow nvm for me trying to get the bot to print stuff
where on your code you getting stuck?
one sec
idk how to make it go down and then print out the correct number of asteriks
actually wait i think i know how to make it go down correctly but the number of asteriks still i dont know how to get it correctly
well how do you think you could do it?
to make it go down i can just put the code outside of the for loop for the asterisks
and for the asterisks i think i can make a formula so it prints out correctly
but that part im stuck
the asterisks part
the easiest way imho is to just split it in 2 parts, the ascending and descending part
I mean you do have that already:
for(i = 0; i < num; i++)
{
for(j = 0; j < num; j++)
{
cout << "*";
}
}
i get this output
well your code is close
a minor modification can get you this:
*
**
***
****
for(j = 0; j < num; j++)
that loop condition isn't very logical
yeah
but what do I change about it
well spoiling it would be spoonfeeding :D
what do you want that loop logically to do?
yea
where does it give you a number that has that property
that starts out as 0, then 1 then 2 etc
j?
no
very important actually
for (i = 1; i <= num; i++)
{
for (j = 0; j < i; j++)
{
cout << "*";
}
std::cout << "\n";
}
take a look at this slightly edited code
mhmm
okay so if num is 3
it goes in
first for loop i = 1
second for loop j = 0, i = 1
so it only prints once
then
i = 2
again second for loop j = 0 i = 2 so it prints twice
ohhh
yup :)
okay thank you
you're a good teacher
okay so for the descending part
imma try
wait
for(i = 1; i <= num; i++)
{
for(j = 0; j < i; j++)
{
cout << "*";
}
cout << "\n";
for(z = 0; z < num - i; z++)
{
cout << "*";
}
cout << "\n";
}```
i tried this but got a very confusing output
ah yeah, that descending loop would need to be further out
for (i = 1; i <= num; i++)
{
for (j = 0; j < i; j++)
{
cout << "*";
}
std::cout << "\n";
}
<-- same code but now descending
yeah after the first loop is done
for (i = 1; i <= num; i++)
{
for (j = 0; j < i; j++)
{
cout << "*";
}
std::cout << "\n";
}
for (i = 1; i <= num; i++) <-- now this loop needs to change
{
for (j = 0; j < i; j++)
{
cout << "*";
}
std::cout << "\n";
}
kinda like this
Oh so theres another seperate for loop?
for (i = 1; i <= num; i++)
{
for (j = 0; j < i; j++)
{
cout << "*";
}
std::cout << "\n";
}
for (i = 1; i <= num - i; i++)
{
for (j = 0; j < i; j++)
{
cout << "*";
}
std::cout << "\n";
}
Like that?
Im on mobile cause im on the move
yeah this be the easiest way
Oh
you have some duplicate code now ands stuff but this is the simplest way
that 2nd loop is most likely wrong still
for (i = 1; i <= num - i; i++)
most likely want to loop from num - 1 to 0
@wind karma Has your question been resolved? If so, run !solved :)
!solved
You can only solve threads you own
Bruh nvm
!solved
Thank you and let us know if you have any more questions!
Thank you and let us know if you have any more questions!