### stars doesn't space properly

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960`` `````` #include "stdafx.h" #include using namespace std; void line2(int,int,int); int main() {int i; do {cout<<"How many rows? "; cin>>i; if(i<0) cout <<" must be nonnegative\n "; cout << " "; }while(i<0); line2(1,1,i); system("pause"); return 0; } void line2(int m,int n,int p) {int i; if(m0) cout<

My code compiles just fines but stars are suppose to be in the middle but it doesn't space correctly, any ideas why or how to fix it???

 ``1234567`` `````` * * * * * * * * * * * * * * * * ``````

above image is how its suppose to show but it all starts in first line instead of making the correct shape. Thanks
Last edited on
Comment line #24
line 24 is suppose to space it out. although i does give it one space out it still doesn't show the correct format??
Comment line #24
 `Comment line #24 `
And the winner for most useless answer is here.

who cares, you need to output nessesary number of spaces before your first star.
Fixed (slightly) function:
 ``12345678910111213141516`` ``````void line2(int m,int n,int p) { if(m0) cout<
If you didn't know it, in such problems (star printing problems) you should first write general formula and then code using loops (unless you are forced by your professor to use recursion):
`n-r " " and r "* "`
where n is inputted at the beginning of the program (in your case 4)
and `r varies from 1 to n and then n-1 to 1`.
Last edited on
MiiNipaa,

I can't thank you enough!!!

Sharma,

Thanks, but for this assignment i had no choice but to use recursion.
and point taken.
Topic archived. No new replies allowed.