C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 25th, 2003, 10:54 PM
ShawnD ShawnD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 56 ShawnD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to ShawnD
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.
__________________
PHP is fun

Last edited by ShawnD : April 25th, 2003 at 10:57 PM.

Reply With Quote
  #2  
Old April 26th, 2003, 05:58 AM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,327 7stud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 50 sec
Reputation Power: 9
"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.

Reply With Quote
  #3  
Old April 26th, 2003, 01:43 PM
ShawnD ShawnD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 56 ShawnD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to ShawnD
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.

Reply With Quote
  #4  
Old April 26th, 2003, 02:18 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,867 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 2 h 46 m 57 sec
Reputation Power: 480
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.

Reply With Quote
  #5  
Old April 26th, 2003, 02:34 PM
ShawnD ShawnD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 56 ShawnD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to ShawnD
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


btw, it works now. thanks

Last edited by ShawnD : April 26th, 2003 at 03:23 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > same compiler, diff comps, 1 can't compile


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT