I have to print a triangle in C++ where the length is double the height and base of the triangle it is to be isosceles

this is my Isosceles code. how do I change the length base and width so that the length is double. We are only allowed to use stuff up to for loops nothing too fancy. Thank you!

#include <stdio.h>

int main(void)
int i;

for (i = 0; i < 1; ++i) {
printf(" *\n"
" *\n"
" **\n"
" ***\n"
" ****\n"
" *****\n"
" ******\n"
" *******\n"
" ********\n"
" *********\n"
" **********\n"

return 0;

Recommended Answers

All 6 Replies

What you have there is simply a hard coded triangle. You need to write the code to setup the triangle's height and width. Give it a shot and post your problem once you try it.

I know i have to declare the Variables height base and length

int i, base, hieght, length 
for (i = 0; i< 1; ++1) {
"hieght= 10"
"base= 10"
"length= 20"}

Here you have declared the variables, but then output just constant expressions...

I'd suggest googling for "basic c++" and trying some of the simple examples you find until you get familiar with the basics. Then you can try to write this triangle program as a demonstration to yourself that you've learned something!


Well i know how to do basic programming, I am in a class. I just do not know what to do next. Hence why I am asking on the forum. They are always my last resort. That is exactly what I do, I do basic programs first and then I elaborate on those. But I am entirely lost on where to go from my basic triangle program.

Like this?

#include <iostream>
using namespace std;
int main()
	int dimension, number=0;
	cout << "Please enter a number, so I may calculate the size of your triangle: ";
	cin >> dimension;
	for(int x=0;x<=dimension;x++)
		for(int x=0;x<number;x++)
			cout << "*";
		cout << endl;
	cout << endl;

if it shows the triangle after calculating then it should be ok. Thank a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.