Help pls. Very stressed over this as its either ridiculously simple or inherent to codeblocks. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Help pls. Very stressed over this as its either ridiculously simple or inherent to codeblocks.

Hi So basically this is my code; (very simple) im beginner! #include <iostream> using namespace std; int main () int num = 1; while (num < 6) (cout << "number: " << num << endl ; num = num + 1); return 0; and these are my bugging errors; ||=== Build: Debug in Conditional2 (compiler: GNU GCC Compiler) ===| C:\Users\Andrew\CodeBlocks\MinGW\bin\Conditional2\main.cpp|7|error: expected initializer before 'int'| C:\Users\Andrew\CodeBlocks\MinGW\bin\Conditional2\main.cpp|8|error: expected unqualified-id before 'while'| C:\Users\Andrew\CodeBlocks\MinGW\bin\Conditional2\main.cpp|10|error: 'num' does not name a type| C:\Users\Andrew\CodeBlocks\MinGW\bin\Conditional2\main.cpp|11|error: expected unqualified-id before 'return'| ||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 7 second(s)) ===| Any help, Id be most grateful. Thanks!! Andrew

6th Feb 2018, 1:44 PM
Ac1
Ac1 - avatar
18 Answers
+ 6
#include <iostream> using namespace std; int main() { int num = 1; while (num < 6 ){ cout<< "Number: " <<num <<endl; ++num;/*< Same as num = num+1*/ } return 0; }
6th Feb 2018, 2:08 PM
D_Stark
D_Stark - avatar
+ 5
if you paste my answer into playground it will work exactly how you want it.
6th Feb 2018, 4:00 PM
D_Stark
D_Stark - avatar
+ 2
Right click on your src folder in the file navigator on the left, and then 'new file' or 'new...'
9th Feb 2018, 2:56 PM
Zeke Williams
Zeke Williams - avatar
+ 1
Your code needs brackets for the main function
6th Feb 2018, 1:49 PM
spcan
spcan - avatar
+ 1
int main(){ int num;
6th Feb 2018, 2:28 PM
Omar Alkhateeb
+ 1
Copy and paste Omar's code, don't type it yourself, because you still have bracket mistakes; you put the bracket afer 'int num = 1;' and it should be before that
6th Feb 2018, 3:10 PM
Zeke Williams
Zeke Williams - avatar
+ 1
f ing hell!!! it just worked , no change from b4 pasting omars answer. but im happy now !! mayb cos i shut down twice! luv it
6th Feb 2018, 4:02 PM
Ac1
Ac1 - avatar
0
i tried this. nothing. the main which is causing this screwy code is ; 'expected ')' before ';' token. what is this? as the rest i can fix if needed
6th Feb 2018, 1:56 PM
Ac1
Ac1 - avatar
0
#include<iostream> using namespace std; int main(){ int num=1; while(num<6){ cout<<"number:"<<num<<endl; num=num+1;} return 0;}
6th Feb 2018, 2:02 PM
Omar Alkhateeb
0
Thanks Omar; so wot is wrong with this; #include <iostream> using namespace std; int main() int num = 1;{ while (num < 6){ cout << "number: " << num << endl; ++num;} return 0;} error is ; ||=== Build: Debug in Conditional2 (compiler: GNU GCC Compiler) ===| C:\Users\Andrew\CodeBlocks\MinGW\bin\Conditional2\main.cpp|6|error: expected initializer before 'int'| C:\Users\Andrew\CodeBlocks\MinGW\bin\Conditional2\main.cpp|6|error: expected unqualified-id before '{' token| ||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 3 second(s)) ===| narrowing it down!! i think you missed to declare the variable 'int' but i put that in anyway. pls check wot i got back above. thanks!!
6th Feb 2018, 2:26 PM
Ac1
Ac1 - avatar
0
#include <iostream> using namespace std; int main(){ int num; while (num < 6){ cout << "number: " << num << endl; ++num;} return 0;} ||error: ld returned 1 exit status| ??. and i get int num. BUT i thought u always had to declare at least one number to the variable which could always be overwritten anyway, but always at least one number, no?
6th Feb 2018, 3:18 PM
Ac1
Ac1 - avatar
0
int num =1;
6th Feb 2018, 3:23 PM
Omar Alkhateeb
0
mate thanks for all help . my error above (last one) is because an old version of program is runninng. gonna kill it or just restart machine to be dead sure. but thanks!! pray it works..
6th Feb 2018, 3:29 PM
Ac1
Ac1 - avatar
0
no problem
6th Feb 2018, 3:32 PM
Omar Alkhateeb
0
now i just seem to get a blank output screen..u heard this problem?
6th Feb 2018, 3:56 PM
Ac1
Ac1 - avatar
0
i rember all these frustrations / satisfactions from gcse days. long long ago!!
6th Feb 2018, 4:03 PM
Ac1
Ac1 - avatar
0
#include <iostream> using namespace std; int main() { int num = 1; while (num < 6 ){ cout<< "Number: " <<num <<endl; num = num+1; } return 0; }
6th Feb 2018, 4:11 PM
Talluri Saisumanth
Talluri Saisumanth - avatar
0
can anyone pls tell me how to add a blank .cpp file to sources folder in a project? thanks. cant seem to do it from project /add file..
9th Feb 2018, 11:01 AM
Ac1
Ac1 - avatar