472,090 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,090 software developers and data experts.

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.  
Aug 18 '21 #1
1 2987
dev7060
624 Expert 512MB
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.     {
Aug 22 '21 #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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.