#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    56
    Rep Power
    13

    same compiler, diff comps, 1 can't compile


    i made a simple script to find total resistance through a parallel circuit on a friend's computer. i compiled it using Dev C++ 4 and it worked perfectly. i sent the code to my own computer and using the same compiler, Dev C++ 4, it absolutely refused to compile on my computer. look at this code

    PHP Code:
    #include <iostream.h> 
    #include <stdlib.h> 
    int main() { 
        
    int n 1//resistor number
        
    float resistor//resistance of a given resister
        
    float reciprical_sum 0//sum of resistance recipricals
        
    float resistance//total resistance, reciprical of reciprical_sum
        
    cout << "enter resistance, enter 0 to quit \n";
        while (
    resistor !=0) {
    _ _       cout << "resistor " << << ": ";
      
    _ _ cin >> resistor;
    _   _ if (resistor != 0) {
    _ _   _ _reciprical_sum += (resistor);
    _ _   }
    _ _   cout << "\n";
    _ _   ++n;
        }
        
    resistance = (reciprical_sum);
        
    out << "total resistance: " << resistance << "\n";
        
    system("PAUSE");
        return 
    0;

    here are the errors

    10 c:\dev-c_~1\parall~1.cpp
    parse error before character 0240
    18 c:\dev-c_~1\parall~1.cpp
    ANSI C++ forbids declaration `resistance' with no type
    18 c:\dev-c_~1\parall~1.cpp
    `reciprical_sum' was not declared in this scope
    19 c:\dev-c_~1\parall~1.cpp
    syntax error before `<'
    20 c:\dev-c_~1\parall~1.cpp
    ANSI C++ forbids declaration `system' with no type
    20 c:\dev-c_~1\parall~1.cpp
    `int system' redeclared as different kind of symbol
    283 c:\dev-c_~1\include\stdlib.h
    previous declaration of `int system(const char *)'

    20 c:\dev-c_~1\parall~1.cpp
    initialization to `int' from `const char *' lacks a cast
    21 c:\dev-c_~1\parall~1.cpp
    parse error before `return'

    notice the line in bold. Dev C++ tried to tell me that even one of the include files is wrong.




    ok windows is a POS because every time i try to paste stuff from my source file, it keeps putting underscores into my post!!!!
    just disregard all underscores in that posted code except for one of the float names.
    Last edited by ShawnD; April 25th, 2003 at 10:57 PM.
    PHP is fun
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    "i made a simple script to find total resistance through a parallel circuit on a friend's computer."

    Maybe any programs dealing with parallel resistance won't compile on more than one computer using Dev C++ 4?

    Have you ever successfully compiled a program on your computer using Dev C++ 4?

    "ok windows is a POS because every time i try to paste stuff from my source file, it keeps putting underscores into my post!!!!"

    I've never had that problem.
    Last edited by 7stud; April 26th, 2003 at 06:01 AM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    56
    Rep Power
    13
    um did you even read my post? it clearly states that it can compile on my friend's computer but not mine.

    both computers run WinXP if that matters.
    PHP is fun
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    The two IDEs are probably configured differently. To solve the mystery, you should compare your compiler options with your friend's. It's possible that yours is set to a stricter level than his. Sorry, I rarely use the Dev-C++ IDE, so I cannot suggest which menu to find the compiler options under.

    If yours is set to be stricter, then I might have spotted what it's choking on:

    Code:
    ...
        float resistor; //resistance of a given resister
        float reciprical_sum = 0; //sum of resistance recipricals
        float resistance; //total resistance, reciprical of reciprical_sum
        cout << "enter resistance, enter 0 to quit \n";
        while (resistor !=0) {
    _...
    In the while, you are comparing a float variable to an integer constant. Your friend's compiler probably automatically converts the integer zero to a float, while yours won't. Also, you are assigned an integer to the float reciprical_sum, though an assignment is usually more accommodating with regard to automatic type conversion than a comparison operation is.

    I would have written:
    Code:
    ...
        float resistor; //resistance of a given resister
        float reciprical_sum = 0.0F; //sum of resistance recipricals
        float resistance; //total resistance, reciprical of reciprical_sum
        cout << "enter resistance, enter 0 to quit \n";
        while (resistor != 0.0F) {
    _...
    Please let us know if that fixes it.

    Please note that a double is the default floating-point data type. Therefore, a floating-point constant that is not a double must have a qualifying suffix: f or F for float and L or l for long double.

    For that matter, do you have a compelling reason to use a float instead of a double?
    Last edited by dwise1_aol; April 26th, 2003 at 02:23 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    56
    Rep Power
    13
    my book (Practical C++ Programming) says that float is completely different from double.



    it's float for 2 reasons.
    -the most accurate a resistor can be is +-5%. having the ability to do like 15 significant digits instead of 6 really doesn't make it more accurate.
    -double takes twice as much memory.

    obviously memory is not a problem with a little dinky 20 line script but it's best to be a responsible programmer whenever possible and not a Microsoft style programmer :D


    btw, it works now. thanks :)
    Last edited by ShawnD; April 26th, 2003 at 03:23 PM.
    PHP is fun

IMN logo majestic logo threadwatch logo seochat tools logo