Write the same code using the designed loop structure. You are not writing complete programs!
Ask the user to enter her full name. (Read into a string variable.) Determine the number of characters in her name and then write the name to the screen that many times. Illustrate this task using both a for loop and while loop.
```
string name;
cout << "\n Enter your name: ";
getline(cin,name);
int i;
int totalLength = name.size();
int length = totalLength;
//count spaces in name, decrement length
for(i = 0; i < totalLength; ++i)
{
if(name.at(i) == ' ')
length--;
}
cout << "\n Write with a while loop " << length << " times.";
i = 0;
while(i < length)
{
cout << "\n" << name;
++i;
}
cout << "\n Write with a for loop " << length << " times.";
for(i = 0; i < length; ++ i)
{
cout << "\n" << name;
}
```
You might also like to view...
In a program, statements that are ignored (not processed) by the computer are __________.
Fill in the blank(s) with correct word
As shown in the accompanying figure, most operating systems require that users correctly enter a user name and password before they can access the data, information, and programs stored on a computer, mobile device, or network.
Answer the following statement true (T) or false (F)