0

Try to figure out how to use while but something went WRONG

I use cppDroid #include <iostream> using namespace std; int num = 0; while (num < 20) { cout << "Number: " << num << endl; num++; } The output is /buildSources/while.cpp:5:1: error:expected unqualified_id before 'while' while (num < 20){ ^ Return code is not 0 Can someone help me?

25th Jun 2018, 1:40 PM
silencer 45
silencer 45 - avatar
8 Réponses
+ 2
// So it's true that we need to do everything here huh. #include <iostream> using namespace std; int main() { int num = 0; while (num < 20) { cout << "Number: " << num++ << endl; } }
25th Jun 2018, 2:38 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Your main function is missing.
25th Jun 2018, 1:55 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
really thankful for spending time on my question,can't be more appreciate
25th Jun 2018, 2:54 PM
silencer 45
silencer 45 - avatar
+ 1
thank you guys,i will give it a try
25th Jun 2018, 1:57 PM
silencer 45
silencer 45 - avatar
+ 1
silencer 45 Or you might consider a reverse solution besides your original approach as //... int main() { int num = 20; while (num--) cout << num << endl; } Output : 19 18 . . . 1 0
25th Jun 2018, 3:19 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
0
I guess that's because you forgot int main()
25th Jun 2018, 1:56 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar
0
sorry guys,but nope
25th Jun 2018, 2:13 PM
silencer 45
silencer 45 - avatar
0
i tried int main() and down below is int num = 0; only int main() and pops out except initializer before while
25th Jun 2018, 2:20 PM
silencer 45
silencer 45 - avatar