Thread: error: expected unqualified-id before '{' token

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    7

    error: expected unqualified-id before '{' token

    I'm writing a program to make sure I understand the for statement. It is a program that computes the resistance of a network of resistors. I get the following error.

    error: expected unqualified-id before '{' token
    I am using code blocks on XP with the G++ compiler.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int resitors; //amount of resistors the user enters
    float resistance; //the output value, the resistance of the resistors in ohms
    int resistor_value; //allows user to input value of resistors one at a time
    int counter; //used to count
    
    {
        resistance = 0;
        resist = 0; //initializing variables
        cout << "How many resistors?\n";
        cin  >> resistors;
    
        for  ( resitors < counter, ++counter) 
        {
            cout << "What is the resistence of the number " << counter << " resistor?\n";
            cin  >> resistor_value;
    
            resist += resistor_value;
        }
    
        resistance = (resist / resitors);
    
        cout << "The resistence is " << resistance << " ohms.\n";
        return(0);
    }
    Thanks in advance,


    fhbwghads

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You need three things inside the parentheses of a for-statement. (Notice also that you get a line number for your error messages too.)

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    7
    I have changed the for statement to,

    for (counter = 0, resitors < counter, ++counter)
    Still same error, error line is 10 which is the beginning bracket ({).

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Okay. You still have one thing inside the parentheses. Note that things are separated with ; and not ,.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by tabstop View Post
    Okay. You still have one thing inside the parentheses. Note that things are separated with ; and not ,.
    It seems to be none of your instructions are actually inside a function...

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, main is missing. Plus the variables should really be inside main, not globals.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Parsing and Tokens (strtok)
    By readerwhiz in forum C Programming
    Replies: 6
    Last Post: 04-22-2002, 09:57 AM