Hello everyone, I came across this question and it's driving me crazy that I don't seem to know how to start writing the code necessary.
So the question is:
write a function called sawWave that will take the integer parameters nteeth and amp and produce a “Drawing” of saw-tooth wave with nteeth “teeth” and amplitude (max tooth width) of amp. Your function should be written so that the parameter amp will default to 5. No value should be returned. Example, calling your function with nteeth = 2 and amp =4 should produce the output (two teeth of width four):
You would need to write three nested for loops. The outer one will iterate over teeth 0<=i<nteeth. The middle loop will iterate over the lines in a tooth 0<=j<amp. The inner loop prints * on the line from 0<=k<j. Note that in the middle loop, after you execute the inner loop, you need to print a new line character. And from what you have pasted, it looks like there is a new line in the outer loop, after the execution of the middle loop.
void DIYPrint(char c, int nteeth, int amp=5)
{
int i,j,k;
for (i=1;i<=nteeth;i++)
{
for (j=1;j<=amp;j++)
{
for (k=1;k<=j;k++)
{
cout<<c;
}
cout<<endl;
}
if(i!=nteeth)
cout<<endl;
}
}