473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 3374
dev7060
633 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

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

Similar topics

3
by: Alan G Isaac | last post by:
from Numeric import * p = array() q = array() print logical_or(p,q) #expected result print (p or q) #prints p This might be expected, except for the documentation:...
4
by: spilich | last post by:
I have a large table that I recently purged a year of data from. However, the table size in sp_spaceused hasn't decreased as much as I would expect. (there are no text or large object columns on...
4
by: Bill | last post by:
I call a function in my .js file like this: onClick="location.href='blank.html' + generateSearchStringFromForm('section')" where section is the name of my form. The function is defined as...
2
by: Matt | last post by:
Hello all, I have written a collection class that implements IList. The class currently uses an ArrayList for its internal storage. I am somewhat confused as to how I should implement the...
5
by: TJS | last post by:
trying to display pdf file in browser fails on this line: Response.ContentType = "application/pdf" getting an error about no declaration found for "response" what declaration is needed ???
8
by: WvH | last post by:
Hi, When I create a new application, with just one button, then this code works as expected: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
2
by: Radu | last post by:
Hi. I have created a service which watches a folder and if any text file is added to that folder runs a custom encryption scheme on it. I add a file in that folder, and it works fine. However, when...
1
by: kieran04 | last post by:
every time i run this program in VBE i keep getting the message 'Compile Error: expected array' for the two bold lines underneath, please help? Public Function KnotsToKmPerHr(knots As...
7
by: Ibys | last post by:
hi, hoping i have posted this in the right section this time :) i am doing my javascript still, and cant figure out why i keep getting an error: object expected message for validateform() im just...
2
by: neha thakur | last post by:
I am getting an error object expected in IE8 for following code. Could anybody help? $(function() { $('.password').pstrength(); }); This is the highlighted code out of the following code. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.