Yes it is homework, but i really don't know how to solve it. I spend with it about hour.:/
Then spend a few more hours, or days or weeks. Start at the beginning of the book and read and reread till it makes sense. You need some understanding of the basics before this forum can help you.
So how far have you got? Post the code you've got so far (even if it doesn't compile or work) and we'll give you some pointers towards your next steps. As it's homework we can't write the code for you as that would be considered cheating. If you are having trouble learning the basics from your tutor you might want to look at these on-line tutorials for c++.
When you post code, please could you use [code] tags. I should have mentioned this in post #7. Click Go Advanced, select code then click '#'. A couple of pointers.
Code:
cout << symbol << string(i, " ") << endl;
With string() you are trying to create a string of i spaces. However, this will give a compiler error as the space needs to be in single quotes for a character rather than double quotes for a string. Also cout prints from left to right. So you are first printing the symbol and then printing a number of spaces and then a new line!!
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Have you actually tried to compile and run this progam? You need to have a main() function that calls your pyramida() function. As you are using the string class, you will also need to have #include <string> as well togther with using std::string; Try compiling and running this program. Look at the output and then see if you can figure out what else needs to go in the for loop to produce the triangle.
Happy coding
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Bookmarks