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

1st Jan 2017, 10:15 AM
Denis Sidoruk
Denis Sidoruk - avatar
5 ответов
+ 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.
1st Jan 2017, 10:23 AM
Naveen Kumar
Naveen Kumar - avatar
+ 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?
1st Jan 2017, 11:50 AM
Denis Sidoruk
Denis Sidoruk - avatar
+ 1
You need to make loop for increasing x value. Best solution is to make 'for' loop.
1st Jan 2017, 2:59 PM
Dejan Francuz🥇
Dejan Francuz🥇 - avatar
0
What Im need do for bug fix?Sorry , Im bad speak English
1st Jan 2017, 10:31 AM
Denis Sidoruk
Denis Sidoruk - avatar
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...)
1st Jan 2017, 10:48 AM
Leonida17st
Leonida17st - avatar