I'm aware of how to do incremental patterns and there's lots of tutorials on that already, but this multiple-like function I cannot figure out. Would appreciate help, thank you.
And for clarity, every line is a multiple of its self times 2.
So it goes
1
2
4
8
16.
-----------------------------------------------------------------------------------------------------
Here's what I have currently:
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int r=0;
int k=pow(2,r);
for (int r=0; r < 7; r++)
{
for (int c=0; c < k; c++)
{
cout << "+";
}
k=pow(2,r);
cout << endl;
}
return 0;
}
-------------------------------------------------------------------------------------------------
Issue is: I keep getting an extra + when I run it.
+
+
++
+++++
So I'm trying to get rid of the extra, and mirror it downwards.
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int r = 0;
double k;
for (int r = 0; r < 7; r++)
{
k = pow(2, r);
for (int c = 0; c < k; c++)
{
cout << "+";
}
cout << endl;
}
return 0;
}
Yeah I knew the placement was messing something up , but I should've declared via doubles the K value. I had tried only with the R value. Thanks a million.
By chance, do you know how to loop it backwards like a sideways pyramid using the same function? Perhaps adding:
Ah, but using it within the same loop. I'm only allowed to use the '+' once in my assignment. So I suppose I have to place that line within the first loop somewhere.
Literally: "Your code should have only one '+' "
I need to find a way to use:
for (int r = 5; r >=0; r--)
Without making another cout<<"+" in a new loop because I can only use + once.
int main()
{
int r = 0,back;
double k;
for (int r = 0; r < 13; r++)
{
if (r < 7)
back = r; //Let back increase in value
else
back--; // Start decreasing back variable
k = pow(2, back);
for (int c = 0; c < k; c++)
{
cout << "+";
}
cout << endl;
}
return 0;
}
@DragonflyBeach
So the back function returns the print to for (int r = 0; r < 13; r++) ?
EDIT: Oh I see, its not a function, its just holding for r value.
Very helpful. If/else are likely better than for if I'm restricted to using a statement once.