#include <iostream>
int main(int argc, char *argv[])
{
int numberOfChars = 7;
for (int i = 0; i < numberOfChars; i++)
{
for (int ii = 0; ii < numberOfChars; ii++)
{
if (i < ii)
std::cout << "*";
else
std::cout << " ";
}
std::cout << std::endl;
}
}
Please don't just give him the answers to his homework. Asides from it being cheating, he doesn't learn anything from it and then he'll have to post here again with a new problem because he never learned the lesson from the first problem (programming is cumulative, after all). And if you give him the answer to that problem too, well then he won't learn something for the second time, and will have to post here again. Instead of feeding this cycle, try to just give suggestions and hints without giving away the whole answer.
if he's as interested as i was he'll still learn something from this :)
and if not, well let's hope his prof knows how to test the capabilities of his students :p
anyhow this wasn't much of a deal i guess ö.ö
but thanks you for your advice, i'll consider it next time
@Gaminic: Well, it's a nested for loop that way and it runs five times.. it's just to print out the asterisks on each line and then continue to the next. Like I said, my excuse is that I've only started learning about a week ago. Sorry.
for(int column=0; column<1; column++){
switch(spaceCount){
case 6: cout << " "; break;
case 5: cout << " "; break;
case 4: cout << " "; break;
case 3: cout << " "; break;
case 2: cout << " "; break;
default: cout << "Error";
}
that loop will only run once, besides, spaceCount is outside of the larger for loop, so it would output 6 spaces 5 times, and then the program would end.
there are other problems as well, that would make it not work, if you are beginning to program in c++ I suggest you first compile everything.
@Zephilinox: I know what he meant. That loop is called five different times from within the other for loop. The "spaceCount--" is within the first for loop and is initialized outside of main. (Meaning all classes/functions should have access to it)
I don't understand..? It worked perfectly fine on my compiler.
I use Code::Blocks.
You're right, I'm sorry, I mixed up the brackets, I'm not used to seeing them split up the way you've done it, I thought the first } was ending the column loop, so space count would be outside the row loop, and outputting the array wouldn't work because it was outside the column loop (where int column is defined)
@Zephilinox: No problem, it was my fault. I guess I need to change my syntax to make it easier to read if I do continue my pursuit in learning to program. That's just the way I've learned how.
No it isn't, there are many ways of indenting and formatting code, yours is a valid one, I'm simply not used to reading it.
I believe most Java programmers do it the way you've done it, might be wrong though.
PitDaAnimA has also used a different style, by using 8 spaces instead of 4, 4 being the standard spacing for [TAB], some people use 2.
some people also like placing the beginning { at the start, then some code, then the rest of the code on other lines, and ending with } on its own line.