Triangle.

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2009
Posts: 16
Reputation: jjf3rd77 is an unknown quantity at this point 
Solved Threads: 0
jjf3rd77's Avatar
jjf3rd77 jjf3rd77 is offline Offline
Newbie Poster

Triangle.

 
0
  #1
25 Days Ago
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!

  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int i;
  6.  
  7. for (i = 0; i < 1; ++i) {
  8. printf(" *\n"
  9. " *\n"
  10. " **\n"
  11. " ***\n"
  12. " ****\n"
  13. " *****\n"
  14. " ******\n"
  15. " *******\n"
  16. " ********\n"
  17. " *********\n"
  18. " **********\n"
  19.  
  20. }
  21. return 0;
  22. }
Knowledge is earned, Education is learned.- me
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 629
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster
 
0
  #2
25 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 16
Reputation: jjf3rd77 is an unknown quantity at this point 
Solved Threads: 0
jjf3rd77's Avatar
jjf3rd77 jjf3rd77 is offline Offline
Newbie Poster

is this right or on the right path

 
0
  #3
25 Days Ago
I know i have to declare the Variables height base and length

  1. int i, base, hieght, length
  2. for (i = 0; i< 1; ++1) {
  3. printf("*\n"
  4. "hieght= 10"
  5. "base= 10"
  6. "length= 20"}
Last edited by jjf3rd77; 25 Days Ago at 8:22 pm.
Knowledge is earned, Education is learned.- me
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 629
Reputation: daviddoria is a jewel in the rough daviddoria is a jewel in the rough daviddoria is a jewel in the rough 
Solved Threads: 46
daviddoria daviddoria is offline Offline
Practically a Master Poster
 
0
  #4
25 Days Ago
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!

Dave
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 16
Reputation: jjf3rd77 is an unknown quantity at this point 
Solved Threads: 0
jjf3rd77's Avatar
jjf3rd77 jjf3rd77 is offline Offline
Newbie Poster
 
0
  #5
25 Days Ago
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.
Knowledge is earned, Education is learned.- me
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 128
Reputation: restrictment is on a distinguished road 
Solved Threads: 9
restrictment's Avatar
restrictment restrictment is offline Offline
Junior Poster
 
0
  #6
25 Days Ago
Like this?
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int dimension, number=0;
  6. cout << "Please enter a number, so I may calculate the size of your triangle: ";
  7. cin >> dimension;
  8. for(int x=0;x<=dimension;x++)
  9. {
  10. for(int x=0;x<number;x++)
  11. cout << "*";
  12. cout << endl;
  13. number++;
  14. }
  15. cout << endl;
  16. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 16
Reputation: jjf3rd77 is an unknown quantity at this point 
Solved Threads: 0
jjf3rd77's Avatar
jjf3rd77 jjf3rd77 is offline Offline
Newbie Poster
 
0
  #7
25 Days Ago
if it shows the triangle after calculating then it should be ok. Thank a lot!
Knowledge is earned, Education is learned.- me
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC