// the code needs to display the string twice on the first line
//four times on the second line and six times on the third
//But idk how to make it do that with the while loop
#include <iostream>
#include <cmath>
#include <string>
usingnamespace std;
int main()
{
string first; // holding the string value
int temp = 3; // condition for while loop
int second = 0; // counter variable
cout << "Enter in the string you want to repeat:";
cin >> first; // get the string
cout << endl;
while (second < temp)
{
cout << first << first << endl;
second += 1;
}
return 0;
}
while (second < temp)
{
for(int i=1; condition; i++)
cout << first << " ";
cout << endl; // this endl happens outside the for-loop
second += 1;
}
So the first time the loop iterates twice. On the next while loop the for-loop should iterate 4 times. On the last while loop the for-loop should iterate 6 times.
So think about what 'condition' would be. You'll need to declare and initialize a variable outside the while-loop for this 'condition'. Since the iterations will go from 2 to 4 to 6, you know that the condition will have to modified every time you exit the for loop. Think about how you would modify it.