0
Help , what wrong?
int main() { int lvl = 0; int xp = 0; if (xp == 0) { cout <<"Welcome"; int lvl = 1; } if (xp == 1000) { cout << "Lvl up"; int lvl = 2; } if (xp == 1500) { cout << "Lvl up"; int lvl = 3; } return 0; } What wrong in int main?Have error
5 Answers
+ 1
If you initialize xp with 0 inside the main there is no chance of getting it's value 1000 or 1500 in this code section. So, the second and third if condition will never be true until we changes xp's value by any function.
+ 1
int main()
{
int lvl = 0;
int xp = 0;
if (xp == 0) {
cout <<"Welcome";
lvl = 1;
}
if (xp == 1000) {
cout << "Lvl up";
lvl = 2;
}
if (xp == 1500) {
cout << "Lvl up";
lvl = 3;
}
return 0;
}
WTF?
+ 1
You need to make loop for increasing x value. Best solution is to make 'for' loop.
0
What Im need do for bug fix?Sorry , Im bad speak English
0
you don't need to initialize variable 2 times...you said int lvl = 0; and your first if there is int lvl=1;
but you already have variable lvl .now you just write lvl=1; --> same thing for every variable
Conclusion:
Initialize variable only once and then change it value without writing any type(int,floar,char...)