| | |
type 'double' unexpected
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 26
Reputation:
Solved Threads: 0
hey i got some c homework due Monday and I'm stuck. please help me. I'm going to mark the error lines with **** in place of a tab. build errors are at the bottom. i will be eternally grateful for any insight.
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(88) : error C2062: type 'double' unexpected
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(90) : error C2065: 'difflatt' : undeclared identifier
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(92) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
not that i get these errors when i build but not when i compile
c Syntax (Toggle Plain Text)
//patrick allard //program4 //prof ed ryder #include "stdio.h" #include "stdlib.h" #include "math.h" void main() { //declare input variables double lat1, lat2, lat3, long1, long2, long3; //aquire input values from user printf("\nEnter position of way point 1 \(latitude and longitude\)\: "); scanf("%lf %lf", &lat1, &long1); printf("\nEnter position of way point 2 \(latitude and longitude\)\: "); scanf("%lf %lf", &lat2, &long2); //convert degrees to radians lat1=lat1*.017453; lat2=lat2*.017453; long1=long1*.017453; long2=long2*.017453; //make suure difflat and difflong are within domain of function cos double difflat1=fabs(lat1-lat2); double difflong1=fabs(long1-long2); while (difflat1>6.2832) { difflat1=difflat1-6.2832; } while (difflong1>6.2832) { difflong1=difflong1-6.2832; } //makesure asineparam is within the domain of function asin double asinparam1=sqrt(fabs(1.0-.5*cos(difflat1)-.5*cos(difflong1))); while (asinparam1>1) { asinparam1=asinparam1-2; } //declare and assign distance output variable double d1=asin(asinparam1)*2.0*3963.1; //display desired output printf("\nDistance traveled =%6.1lf miles", d1); double pathd=d1; do{ //aquire input values from user printf("\nEnter position of way point 3 \(latitude and longitude\)\: "); lat3=EOF; long3=EOF; scanf("%lf %lf", &lat3, &long3); //how to break the loop if (lat3=EOF) { break; } if (long3=EOF) { break; } //convert degrees to radians double lat3=lat3*.017453; double long3=long3*.017453; //make suure difflat and difflong are within domain of function cos **** double difflat2=fabs(lat2-lat3); double difflong2=fabs(long2-long3); **** while (difflat2>6.2832) { **** difflat2=difflat2-6.2832; } while (difflong2>6.2832) { difflong2=difflong2-6.2832; }; //makesure asineparam is within the domain of function asin double asinparam2=sqrt(fabs(1.0-.5*cos(difflat2)-.5*cos(difflong2))); while (asinparam2>1) { asinparam2=asinparam2-2; } //declare and assign distance output variable double d2=asin(asinparam2)*2.0*3963.1; pathd=pathd+d2; //display desired output printf("\nDistance traveled =%6.1lf miles", pathd); } while (1==1); //make suure difflat and difflong are within domain of function cos double difflatt=fabs(lat1-lat3); double difflongt=fabs(long1-long3); while (difflatt>6.2832) { difflatt=difflatt-6.2832; } while (difflongt>6.2832) { difflongt=difflongt-6.2832; } //makesure asineparam is within the domain of function asin double asinparamt=sqrt(fabs(1.0-.5*cos(difflatt)-.5*cos(difflongt))); while (asinparamt>1) { asinparamt=asinparamt-2; } //declare and assign distance output variable double dt=asin(asinparamt)*2.0*3963.1; //display desired output printf("\n\n Total Distance traveled =%6.1lf miles\nStart to finish distance =%6.1lf miles", pathd, dt); }
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(88) : error C2062: type 'double' unexpected
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(90) : error C2065: 'difflatt' : undeclared identifier
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(92) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
not that i get these errors when i build but not when i compile
Last edited by Ancient Dragon; Feb 23rd, 2008 at 5:12 pm. Reason: add line numbers for convenyance
line 8: void main()
main NEVER EVER returns void. It always returns an integer.
line 15: unrecognized escape character "\(" as well as "\)" and "\:". You can't escape those characters, just delete the "\" character.
Those same errors appear several more times in your code. Correct them and the rest of your program will compile ok.
main NEVER EVER returns void. It always returns an integer.
line 15: unrecognized escape character "\(" as well as "\)" and "\:". You can't escape those characters, just delete the "\" character.
Those same errors appear several more times in your code. Correct them and the rest of your program will compile ok.
Last edited by Ancient Dragon; Feb 23rd, 2008 at 5:19 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
[threadjack]
Riddle me this, since it is something I've wondered about for a long time...
Why does one take the exact source of a problem and then twiddle it such that it will produce errors other than those of concern that for all intents and purposes needs to be re-tweaked back to what one had originally -- when the language itself offers comments very well suited to this exact purpose?
I'm just using the above as an example: why not the following?
I'm not nit-picking this one case, I've seen dozens of variants. I'm just wondering if anyone can shed light on this matter.
•
•
•
•
hey i got some c homework due Monday and I'm stuck. please help me. I'm going to mark the error lines with **** in place of a tab.
C Syntax (Toggle Plain Text)
**** double difflat2=fabs(lat2-lat3); double difflong2=fabs(long2-long3); **** while (difflat2>6.2832) { **** difflat2=difflat2-6.2832; }
Why does one take the exact source of a problem and then twiddle it such that it will produce errors other than those of concern that for all intents and purposes needs to be re-tweaked back to what one had originally -- when the language itself offers comments very well suited to this exact purpose?
I'm just using the above as an example: why not the following?
C Syntax (Toggle Plain Text)
/* ERROR */ double difflat2=fabs(lat2-lat3); double difflong2=fabs(long2-long3); /* ERROR */ while (difflat2>6.2832) { /* ERROR */ difflat2=difflat2-6.2832; }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Feb 2008
Posts: 26
Reputation:
Solved Threads: 0
my goodness such lightning fast responses. this website is awsome and the community really cares.
i agree, it would be best to mark the errors with /* ERROR */, i didnt think of that.
all of the programs i have created so far have had main return a void.
all of the programs i have created so far gave me warnings about the unrecognised character excape sequences, but it compiled just fine, printing a : and not a /:.
even if i change these things i still have the same problem.
im running msvs6.0
is it my compiler?
i agree, it would be best to mark the errors with /* ERROR */, i didnt think of that.
all of the programs i have created so far have had main return a void.
all of the programs i have created so far gave me warnings about the unrecognised character excape sequences, but it compiled just fine, printing a : and not a /:.
even if i change these things i still have the same problem.
im running msvs6.0
is it my compiler?
•
•
Join Date: Feb 2008
Posts: 26
Reputation:
Solved Threads: 0
heres a new copy of my source with the changes u all requested. still doesnt work any ideas?
--------------------Configuration: patrick allard gps continued source[1] - Win32 Debug--------------------
Compiling...
patrick allard gps continued source[1].cpp
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(88) : error C2062: type 'double' unexpected
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(90) : error C2065: 'difflatt' : undeclared identifier
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(92) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
Error executing cl.exe.
patrick allard gps continued source[1].exe - 2 error(s), 1 warning(s)
C Syntax (Toggle Plain Text)
//patrick allard //program4 //prof ed ryder #include "stdio.h" #include "stdlib.h" #include "math.h" int main() { //declare input variables double lat1, lat2, lat3, long1, long2, long3; //aquire input values from user printf("\nEnter position of way point 1 (latitude and longitude): "); scanf("%lf %lf", &lat1, &long1); printf("\nEnter position of way point 2 (latitude and longitude): "); scanf("%lf %lf", &lat2, &long2); //convert degrees to radians lat1=lat1*.017453; lat2=lat2*.017453; long1=long1*.017453; long2=long2*.017453; //make suure difflat and difflong are within domain of function cos double difflat1=fabs(lat1-lat2); double difflong1=fabs(long1-long2); while (difflat1>6.2832) { difflat1=difflat1-6.2832; } while (difflong1>6.2832) { difflong1=difflong1-6.2832; } //makesure asineparam is within the domain of function asin double asinparam1=sqrt(fabs(1.0-.5*cos(difflat1)-.5*cos(difflong1))); while (asinparam1>1) { asinparam1=asinparam1-2; } //declare and assign distance output variable double d1=asin(asinparam1)*2.0*3963.1; //display desired output printf("\nDistance traveled =%6.1lf miles", d1); double pathd=d1; do{ //aquire input values from user printf("\nEnter position of way point 3 (latitude and longitude): "); lat3=EOF; long3=EOF; scanf("%lf %lf", &lat3, &long3); //how to break the loop if (lat3=EOF) { break; } if (long3=EOF) { break; } //convert degrees to radians double lat3=lat3*.017453; double long3=long3*.017453; //make suure difflat and difflong are within domain of function cos double difflat2=fabs(lat2-lat3); double difflong2=fabs(long2-long3); while (difflat2>6.2832) { difflat2=difflat2-6.2832; } while (difflong2>6.2832) { difflong2=difflong2-6.2832; }; //makesure asineparam is within the domain of function asin double asinparam2=sqrt(fabs(1.0-.5*cos(difflat2)-.5*cos(difflong2))); while (asinparam2>1) { asinparam2=asinparam2-2; } //declare and assign distance output variable double d2=asin(asinparam2)*2.0*3963.1; pathd=pathd+d2; //display desired output printf("\nDistance traveled =%6.1lf miles", pathd); } while (1==1); //make suure difflat and difflong are within domain of function cos /* ERROR */ double difflatt=fabs(lat1-lat3); double difflongt=fabs(long1-long3); /* ERROR */ while (difflatt>6.2832) { /* ERROR */ difflatt=difflatt-6.2832; } while (difflongt>6.2832) { difflongt=difflongt-6.2832; } //makesure asineparam is within the domain of function asin double asinparamt=sqrt(fabs(1.0-.5*cos(difflatt)-.5*cos(difflongt))); while (asinparamt>1) { asinparamt=asinparamt-2; } //declare and assign distance output variable double dt=asin(asinparamt)*2.0*3963.1; //display desired output printf("\n\n Total Distance traveled =%6.1lf miles\nStart to finish distance =%6.1lf miles", pathd, dt); return 0; }
--------------------Configuration: patrick allard gps continued source[1] - Win32 Debug--------------------
Compiling...
patrick allard gps continued source[1].cpp
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(88) : error C2062: type 'double' unexpected
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(90) : error C2065: 'difflatt' : undeclared identifier
C:\Documents and Settings\Luigi Mario\Desktop\patrick allard gps continued source[1].cpp(92) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
Error executing cl.exe.
patrick allard gps continued source[1].exe - 2 error(s), 1 warning(s)
•
•
Join Date: Feb 2008
Posts: 26
Reputation:
Solved Threads: 0
this is baffling. i have no idea what ur suggestion changed, but i no longer get the error. the program runs, but i cant get it to go through the loop, and im getting some pretty strange results. the program is supposed to escape the loop when the user presses ctrl z. i tried making it a while loop, but nothing changed. ive been debugging for a few hours now and i cant figure it out. first lat3 and long3 are assigned EOF, which the debugger thinks is some number -9.225e61, then it goes through the scanf and completely ignores what number i enter and still considers lat3 and long3 to be -9.225e61 heres the new source and my output:
Enter position of way point 1 (latitude and longitude): 1 1
Enter position of way point 2 (latitude and longitude): 2 2
Distance traveled = 97.8 miles
Enter position of way point 3 (latitude and longitude): 3 3
Total Distance traveled = 97.8 miles
Start to finish distance =-8707.0 miles
C Syntax (Toggle Plain Text)
//patrick allard //program4 //prof ed ryder #include "stdio.h" #include "stdlib.h" #include "math.h" int main() {double difflatt; //declare input variables double lat1, lat2, lat3, long1, long2, long3; //aquire input values from user printf("\nEnter position of way point 1 (latitude and longitude): "); scanf("%lf %lf", &lat1, &long1); printf("\nEnter position of way point 2 (latitude and longitude): "); scanf("%lf %lf", &lat2, &long2); //convert degrees to radians lat1=lat1*.017453; lat2=lat2*.017453; long1=long1*.017453; long2=long2*.017453; //make suure difflat and difflong are within domain of function cos double difflat1=fabs(lat1-lat2); double difflong1=fabs(long1-long2); while (difflat1>6.2832) { difflat1=difflat1-6.2832; } while (difflong1>6.2832) { difflong1=difflong1-6.2832; } //makesure asineparam is within the domain of function asin double asinparam1=sqrt(fabs(1.0-.5*cos(difflat1)-.5*cos(difflong1))); while (asinparam1>1) { asinparam1=asinparam1-2; } //declare and assign distance output variable double d1=asin(asinparam1)*2.0*3963.1; //display desired output printf("\nDistance traveled =%6.1lf miles", d1); double pathd=d1; while (1==1) { //aquire input values from user printf("\nEnter position of way point 3 (latitude and longitude): "); lat3=EOF; long3=EOF; scanf("%lf %lf", &lat3, &long3); //how to break the loop if (lat3=EOF) { break; } if (long3=EOF) { break; } //convert degrees to radians double lat3=lat3*.017453; double long3=long3*.017453; //make suure difflat and difflong are within domain of function cos double difflat2=fabs(lat2-lat3); double difflong2=fabs(long2-long3); while (difflat2>6.2832) { difflat2=difflat2-6.2832; } while (difflong2>6.2832) { difflong2=difflong2-6.2832; }; //makesure asineparam is within the domain of function asin double asinparam2=sqrt(fabs(1.0-.5*cos(difflat2)-.5*cos(difflong2))); while (asinparam2>1) { asinparam2=asinparam2-2; } //declare and assign distance output variable double d2=asin(asinparam2)*2.0*3963.1; pathd=pathd+d2; //display desired output printf("\nDistance traveled =%6.1lf miles", pathd); } //make suure difflat and difflong are within domain of function cos /* ERROR */ difflatt=fabs(lat1-lat3); double difflongt=fabs(long1-long3); /* ERROR */ while (difflatt>6.2832) { /* ERROR */ difflatt=difflatt-6.2832; } while (difflongt>6.2832) { difflongt=difflongt-6.2832; } //makesure asineparam is within the domain of function asin double asinparamt=sqrt(fabs(1.0-.5*cos(difflatt)-.5*cos(difflongt))); while (asinparamt>1) { asinparamt=asinparamt-2; } //declare and assign distance output variable double dt=asin(asinparamt)*2.0*3963.1; //display desired output printf("\n\n Total Distance traveled =%6.1lf miles\nStart to finish distance =%6.1lf miles", pathd, dt); for(;;); return 0; }
Enter position of way point 1 (latitude and longitude): 1 1
Enter position of way point 2 (latitude and longitude): 2 2
Distance traveled = 97.8 miles
Enter position of way point 3 (latitude and longitude): 3 3
Total Distance traveled = 97.8 miles
Start to finish distance =-8707.0 miles
>i have no idea what ur suggestion changed, but i no longer get the error.
Most likely because Visual C++ 6.0 compiles under C code under the C89 standard. One of the rules in C89 is that all variables must be declared in the current scope before any function calls are made. C99 changed this to allow intermixed function calls and variable declarations, which is why several people told you that your code compiled fine.
As for your code not working, sorry, I don't have time to look over it right now.
Most likely because Visual C++ 6.0 compiles under C code under the C89 standard. One of the rules in C89 is that all variables must be declared in the current scope before any function calls are made. C99 changed this to allow intermixed function calls and variable declarations, which is why several people told you that your code compiled fine.
As for your code not working, sorry, I don't have time to look over it right now.
Last edited by John A; Feb 24th, 2008 at 2:18 am.
"Technological progress is like an axe in the hands of a pathological criminal."
Yes. Why are you still using that ancient compiler? You might as well chizzel out your program on a piece of rock with Hammer & Chizzel
VC++ 6.0 will let you do a lot of things that aren't c++ complient. Download the latest free Microsoft VC++ 2008 Express.
VC++ 6.0 will let you do a lot of things that aren't c++ complient. Download the latest free Microsoft VC++ 2008 Express. Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Polynomials with linked lists (C++)
- SQL Injection Attack (Database Design)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Evaluating sinx between 0 and 14 (C++)
- missing storage-class or type specifiers error (C++)
- Dr Scheme Tutorial (Computer Science)
- help with parrallel arrays (C++)
- Finding length (Java)
- I've got Trojan.Holax... is this bad? (Viruses, Spyware and other Nasties)
- not-a-virusadware (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: good day am new and would like some help with a home work
- Next Thread: for C programmers only
| Thread Tools | Search this Thread |
#include * adobe ansi array asterisks binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list locate looping lowest match matrix meter microsoft number oddnumber opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






