Hello!
I hope there isn't a thread about this already, if there is I blame my real bad skills on searching.. :P
Anyhow, I need to train my knowledge in c++ and decided to make a program that makes a triangle (90 degrees bottom left corner.. Dont know the english word for it.. equilateral?) from what the user types.
Though, I don't understand how I shall use setw / setfill, and I don't get it from the link you sent either..
Pretend that I'm a child, and explain to me ;) Haha
#include <iostream>
using namespace std;
int main (){
int i,j,k,a;
char mat[5][5];
for (i=0;i<5;i++){
for(j=0;j<5;j++){
k=(i-j);
do{
if (k>=0){
mat[i][j]='+';
cout<<mat[i][j];}
else {
cout<<" ";}}
while (a=0);}
cout<<"\n";}
system("PAUSE");
return 0;}
---------------------------------------------------------
copy this and run it...
---------------------------------------------------------
Yeah, that is working alright. But my goal was to let the user designate wich kind of sign (for example: + * / A B 1.. etc. etc.), and then the height of the triangle.
So that it could look like:
1
11
111
*
**
/
///
////
/////
And so on...
If someone could explain to me how to do this, or give me a code to it so that I could analyze it and learn, I'd be overjoyed :)
Thanks for the time you put in though TheNo1, much appriciated! :)
Wow :) Mcleano, I really like it.
It's more simple and effective.
But I think you should add the way we see the triangle (for example the +).
Right now it's showing the triangular shape, by the last number that the user enters.
It's not such a big problem .. The program would be perfect in this manner.
Merry Christmas.... :D
Thanks BettyBoopTS!
That code is a bit easier, I am more on that level than on mcleanos, even though that was good too.
Though I have a question:
To what good is the 37:th line?
(cout << "\n"; )
I mean.. All it does is to cout a new line? And if that line is removed it's not working anymore..
Why is it not possible to only use a << endl; in the "for-section" ?
Looks bad with a cout-line like that, but is it the only solution in this code?
I'm just a beginner myself, and honestly, I may sound like an idiot, but I havnt come across the 'endl' command in the c++ beginners manual i am studying, yet. but,, why does that look bad? i dont understand.
@Helios.
True, none. Though I tried to use it and then nothing worked, and yes I did use it at different locations. (can't remember where though)
Therefore I, probably I was wrong, guessed that it's not possible.
@Betty
Bad is probably wrong choice of words, but in my opinion it looks... My english wordbank is too small right now, so bad is the only word I can figure out..
To only cout out a "\n" looks in my opinon not good, if someone would look at the code. To use a << endl; is "nicer".
Anyhow..
The cout-line is a part of... Let's see.. The loop on line 28, am I right?
That would explain why my <<endl; didn't work since I tried to insert it in the second loop.... :rolleyes: