Hey all,
I have an assignment for my beginning C++ class where my teacher wants us to use recursion to display ten stars ( ********** ) n times vertically. such that if n = 4 it would look like:
**********
**********
**********
**********
now normally I would use a void function that just does:
but my teacher would like us to cout the return of ten stars. How is that supposed to look?Code:void rectangle(int n){ if (n >= 1) cout << "**********"; rectangle (n-1); }
I tried:
but it doesnt seem to be working.Code:#include <iostream> using namespace std; string rectangle(int n){ if (n >= 1) return "**********"; rectangle(n-1); } int main(){ int n; cout << "Please enter an n value: "; cin >> n; cout << rectangle(n); return 0; }
Thanks for any and all help.



LinkBack URL
About LinkBacks



