469,086 Members | 1,192 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,086 developers. It's quick & easy.

Expected unqualified-id before 'for'

Hi all. I am writing a program but I keep getting an error: expected unqualified-id before 'for' in line 29 and I have absolutely no idea what I'm doing wrong... can anyone please help me?


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int  n, x, y;
  6.  
  7.     int number = 0;
  8.     int test = 0;
  9.     int i = 0;
  10.     int k = 0;
  11.     int lines_left = 0;
  12.  
  13.     cout << "Enter an odd number: ";
  14.     cin >> number;
  15.  
  16.     test = number%2;
  17.     i = 1;
  18.     k = number;
  19.     lines_left = k + 4;
  20.  
  21.     if (test == 0)
  22.     {
  23.         cout << "You have entered an invalid number! Please try again." << endl;
  24.         exit(-1);
  25.     }
  26.  
  27.     k = number;
  28.  
  29.     for (k >= 0; k--)
  30.     {
  31.         for (int i = 1; i <= k; i++)
  32.         {
  33.             cout << "*\t";
  34.             cout << "\n";
  35.         }
  36.  
  37.     }
  38.     for (k = 1; k <= number; k++)
  39.     {
  40.         for (i = 1; i <= k; i++)
  41.         {
  42.             cout << "*\t";
  43.             printf("\n");
  44.         }
  45.     }
  46. return 0;
  47. }
  48.  
4 Weeks Ago #1
1 1877
dev7060
485 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1.     k = number;
  2.  
  3.     for (k >= 0; k--)
  4.     {
This
Expand|Select|Wrap|Line Numbers
  1.     k = number;
  2.  
  3.     for ( ; k >= 0; k--)
  4.     {
or (convention)
Expand|Select|Wrap|Line Numbers
  1.     for (k = number; k >= 0; k--)
  2.     {
4 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Alan G Isaac | last post: by
4 posts views Thread by Bill | last post: by
2 posts views Thread by Matt | last post: by
7 posts views Thread by Ibys | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.