you need to take another look at how variables work. i recommend using this site. and i dont know if its just your text editor/ide, but your formatting is horrible
Yeah. You need to learn both how variables work(you used incorrect type), how loops work(you aren't even printing this variable). And as DTS said, try to improve your formatting.
First of all take a look at your variables and what you are trying to do with them.
You are trying(I guess) to input a string into a variable where it only accepts an integer.
Tip: Its always good to initialize variables when you declare them even thought they might not have a valu yet, they can be null.
The people here have given some useful tips. As stated above, please take a look at variables. The int variable is for storing numbers. If you want to store, for example a name, you need to declare the string variable.
And also, I suggest using a for loop. I made a simple code so you can understand the basics:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
int main()
{
std::string name;
constint times = 10;
std::cout << "Please input your name: ";
std::cin >> name;
for (int i = 0; i < times; i++) {
std::cout << name << std::endl;
}
return 0;
}
#include <iostream>
#include <string>
//puts std:: into the namespace so you dont have to.
usingnamespace std;
int main()
{
string name;
int i;
cout<<"Please enter your name: "; getline(cin,name);
for(i=0; i<10; ++i)
{
cout<<name<<"\n";
}
//getline will return your entire string, like if you have Firstname Lastname,
}