#include <iostream>
#include <stdio.h>
#include <string>
usingnamespace std;
int main()
{
string MyName;
cout<<"Hello! May I Have Your First Name?"<<endl;
cout<<"\n";
cin>>MyName;
cout<<"How many times would you want me to display your first name?";
cout<<"\n";
int NamePrnt;
int counter=1;
cin>>NamePrnt;
while(counter<=NamePrnt)
{
cout<< MyName;
cout<< "\n";
counter++;
}
return 0;
}
#include <iostream>
#include <stdio.h>
#include <string>
usingnamespace std;
string MyName;
int NamePrnt;
int counter=1;
int main()
{
cout<<"Hello! May I Have Your First Name?"<<endl;
cout<<"\n";
cin>>MyName;
cout<<"How many times would you want me to display your first name?";
cout<<"\n";
cin>>NamePrnt;
while(counter<=NamePrnt)
{
cout<< MyName;
cout<< "\n";
counter++;
}
return 0;
}
if I use that... now i cannot do the second input..
If you don't know the basic structure of the for loop, here's a basic overview:
The for loop has 4 sections:
1 2
for(Section A; Section B; Section C)
Section D;
Section A) Initialisation. Here, you'll either declare a variable, or assign an existing variable a new value.
Section B) Condition. While this condition is not met (is false), your loop will continue.
Section C) Increment/Decrement. After every cycle (or iteration) of your loop, section C is executed.
Section D) Body. A no-brainer, really.
For more information, go here: http://www.cplusplus.com/doc/tutorial/control/#for