I seem to be getting errors..

I've been trying to understand what's wrong here, I've ever looked up examples of while loops, the samples people give online still produce errors in my IDE. Any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;
 
int main () {
	
int a;

   while( a < 20 ) {
	   
      cout << "value of a: " << a << endl;
      a++;
      
   }
 
   return 0;
}


These are my errors..

expected ')' before ';' token line 5 C/C++ Problem
expected primary-expression before ')' token line 5 C/C++ Problem
expected primary-expression before '<' token line 5 C/C++ Problem

closed account (E0p9LyTq)
Line 7: You are not intializing a to a value. It contains a garbage value you are using to compare in your while loop.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

int main()
{
   int a = 0;

   while (a < 20)
   {
      std::cout << "value of a: " << a << '\n';
      a++;
   }
}
I'm so confused as to how C++ works... I copied and pasted your code & it worked. I re-copied my code and pasted it and it started working. This is frustrating and really hurting my motivation to learn if I'm going to get false errors. grrrrrr
Last edited on
closed account (E0p9LyTq)
however I still get the same errors.

Could be an encoding error with your IDE and original source. You might have typed something not plain text or saved the file as something other than plain text.

It works now, so all it good. :)
Topic archived. No new replies allowed.