Heyy :L (imma supper noobie)

First of all, i'll like to said HI! to all the awesome people on this forum... :3 second... i have this problem as usual that doesnt make any sense :3 can u guy help me out pleasez :O... it's probably ginna look so simple to u... lolz

Im using a compliler called dev c++
herer where i get the error :<

#include <stdlib.h>
#include <iostream>

int counter;

using namespace std;
int main()
{

cout << "This is a Counter to Count from One to Ten (1 - 10)" << endl;



do
counter = counter + 1;
cout << counter; // i get the error here *sad face*

while (counter != 10)


system("PAUSE");
return (0);
}
Last edited on
You are missing the brackets around your do while loop it should look like this:

do
{
counter = counter + 1;
cout << counter;
}while (counter != 10);
First, please use code tags (the <> button to the right when you post or edit a post.) as it makes the code much easier to read, thanks!

Dev C++ is a deprecated compiler, there's a thread somewhere around here about it. I'd suggest getting another, like the free version of VC++ 2010, or Code::Blocks (though you'll have to update some stuff with that one since the GCC compiler that comes with it was recently update to the C++11 standards.)

As far as I can see the only problem is that you are missing an opening brace after the "do". Any loop can only contain one statement. The way you get around this is to make a "block" with open and close braces so you can include more then one statement. You code should look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <stdlib.h>
#include <iostream>

int counter;

using namespace std;
int main()
{

cout << "This is a Counter to Count from One to Ten (1 - 10)" << endl;

do
{
    counter = counter + 1;
    cout << counter; // i get the error here *sad face*
} while (counter != 10);


system("PAUSE");
return 0;

}


Edit: Forgot the ";" after the while test expression. *sad face*

Edit 2: Removed the parentheses around the return value in main.
Last edited on
Opening bracket after "do."
Closing bracket before "while"
No parenthesis around the return value 0.

I'm a newbie in C++ as well. I THINK those are all the errors you're having.

Additionally, I believe you'll need a semicolon after the "while" condition.

I hope this helps.
Last edited on
Thankz A Bunch Phil94, verisimilitude, Raezzor !!! lolz... didnt know it was that simple... :)
oooh and Raezzor a given bigger thanks for spending a little extra time to explain it to me... *send virtually hug* :3

Doh right, no parentheses around return. I missed that when I copied it. And your welcome Handz. Welcome to the forum!
Actually, return (0); is valid. You're forcing the compiler to evaluate (0), which is 0, then to return it. The parenthesis are just extra typing, not an error.
Doh, you are absolutely right. I'm a stickler for details though. :)
Topic archived. No new replies allowed.