type 'double' unexpected

Thread Solved

Join Date: Feb 2008
Posts: 26
Reputation: chopficaro is an unknown quantity at this point 
Solved Threads: 0
chopficaro chopficaro is offline Offline
Light Poster

type 'double' unexpected

 
0
  #1
Feb 23rd, 2008
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.

  1.  
  2. //patrick allard
  3. //program4
  4. //prof ed ryder
  5. #include "stdio.h"
  6. #include "stdlib.h"
  7. #include "math.h"
  8. void main()
  9. {
  10. //declare input variables
  11. double lat1, lat2, lat3, long1, long2, long3;
  12. //aquire input values from user
  13. printf("\nEnter position of way point 1 \(latitude and longitude\)\: ");
  14. scanf("%lf %lf", &lat1, &long1);
  15. printf("\nEnter position of way point 2 \(latitude and longitude\)\: ");
  16. scanf("%lf %lf", &lat2, &long2);
  17. //convert degrees to radians
  18. lat1=lat1*.017453;
  19. lat2=lat2*.017453;
  20. long1=long1*.017453;
  21. long2=long2*.017453;
  22. //make suure difflat and difflong are within domain of function cos
  23. double difflat1=fabs(lat1-lat2);
  24. double difflong1=fabs(long1-long2);
  25. while (difflat1>6.2832)
  26. {
  27. difflat1=difflat1-6.2832;
  28. }
  29. while (difflong1>6.2832)
  30. {
  31. difflong1=difflong1-6.2832;
  32. }
  33. //makesure asineparam is within the domain of function asin
  34. double asinparam1=sqrt(fabs(1.0-.5*cos(difflat1)-.5*cos(difflong1)));
  35. while (asinparam1>1)
  36. {
  37. asinparam1=asinparam1-2;
  38. }
  39. //declare and assign distance output variable
  40. double d1=asin(asinparam1)*2.0*3963.1;
  41. //display desired output
  42. printf("\nDistance traveled =%6.1lf miles", d1);
  43. double pathd=d1;
  44.  
  45. do{
  46. //aquire input values from user
  47. printf("\nEnter position of way point 3 \(latitude and longitude\)\: ");
  48. lat3=EOF;
  49. long3=EOF;
  50. scanf("%lf %lf", &lat3, &long3);
  51. //how to break the loop
  52. if (lat3=EOF)
  53. {
  54. break;
  55. }
  56.  
  57. if (long3=EOF)
  58. {
  59. break;
  60. }
  61. //convert degrees to radians
  62. double lat3=lat3*.017453;
  63. double long3=long3*.017453;
  64. //make suure difflat and difflong are within domain of function cos
  65. **** double difflat2=fabs(lat2-lat3);
  66. double difflong2=fabs(long2-long3);
  67. **** while (difflat2>6.2832)
  68. {
  69. **** difflat2=difflat2-6.2832;
  70. }
  71. while (difflong2>6.2832)
  72. {
  73. difflong2=difflong2-6.2832;
  74. };
  75. //makesure asineparam is within the domain of function asin
  76. double asinparam2=sqrt(fabs(1.0-.5*cos(difflat2)-.5*cos(difflong2)));
  77. while (asinparam2>1)
  78. {
  79. asinparam2=asinparam2-2;
  80. }
  81. //declare and assign distance output variable
  82. double d2=asin(asinparam2)*2.0*3963.1;
  83. pathd=pathd+d2;
  84. //display desired output
  85. printf("\nDistance traveled =%6.1lf miles", pathd);
  86. }
  87. while (1==1);
  88.  
  89.  
  90. //make suure difflat and difflong are within domain of function cos
  91. double difflatt=fabs(lat1-lat3);
  92. double difflongt=fabs(long1-long3);
  93. while (difflatt>6.2832)
  94. {
  95. difflatt=difflatt-6.2832;
  96. }
  97. while (difflongt>6.2832)
  98. {
  99. difflongt=difflongt-6.2832;
  100. }
  101. //makesure asineparam is within the domain of function asin
  102. double asinparamt=sqrt(fabs(1.0-.5*cos(difflatt)-.5*cos(difflongt)));
  103. while (asinparamt>1)
  104. {
  105. asinparamt=asinparamt-2;
  106. }
  107. //declare and assign distance output variable
  108. double dt=asin(asinparamt)*2.0*3963.1;
  109.  
  110.  
  111.  
  112.  
  113. //display desired output
  114. printf("\n\n Total Distance traveled =%6.1lf miles\nStart to finish distance =%6.1lf miles", pathd, dt);
  115. }

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
Attached Files
File Type: cpp patrick allard gps2 source.cpp (3.1 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: type 'double' unexpected

 
0
  #2
Feb 23rd, 2008
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: type 'double' unexpected

 
0
  #3
Feb 23rd, 2008
When I put the code into my compiler, I received the same errors you described. Funnily enough, when I removed the *s, those errors disappeared.
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: type 'double' unexpected

 
0
  #4
Feb 23rd, 2008
[threadjack]
Originally Posted by chopficaro View Post
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.
  1. **** double difflat2=fabs(lat2-lat3);
  2. double difflong2=fabs(long2-long3);
  3. **** while (difflat2>6.2832)
  4. {
  5. **** difflat2=difflat2-6.2832;
  6. }
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?
  1. /* ERROR */ double difflat2=fabs(lat2-lat3);
  2. double difflong2=fabs(long2-long3);
  3. /* ERROR */ while (difflat2>6.2832)
  4. {
  5. /* ERROR */ difflat2=difflat2-6.2832;
  6. }
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.
"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
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 26
Reputation: chopficaro is an unknown quantity at this point 
Solved Threads: 0
chopficaro chopficaro is offline Offline
Light Poster

Re: type 'double' unexpected

 
0
  #5
Feb 23rd, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 26
Reputation: chopficaro is an unknown quantity at this point 
Solved Threads: 0
chopficaro chopficaro is offline Offline
Light Poster

Re: type 'double' unexpected

 
0
  #6
Feb 23rd, 2008
heres a new copy of my source with the changes u all requested. still doesnt work any ideas?

  1.  
  2. //patrick allard
  3. //program4
  4. //prof ed ryder
  5. #include "stdio.h"
  6. #include "stdlib.h"
  7. #include "math.h"
  8. int main()
  9. {
  10. //declare input variables
  11. double lat1, lat2, lat3, long1, long2, long3;
  12. //aquire input values from user
  13. printf("\nEnter position of way point 1 (latitude and longitude): ");
  14. scanf("%lf %lf", &lat1, &long1);
  15. printf("\nEnter position of way point 2 (latitude and longitude): ");
  16. scanf("%lf %lf", &lat2, &long2);
  17. //convert degrees to radians
  18. lat1=lat1*.017453;
  19. lat2=lat2*.017453;
  20. long1=long1*.017453;
  21. long2=long2*.017453;
  22. //make suure difflat and difflong are within domain of function cos
  23. double difflat1=fabs(lat1-lat2);
  24. double difflong1=fabs(long1-long2);
  25. while (difflat1>6.2832)
  26. {
  27. difflat1=difflat1-6.2832;
  28. }
  29. while (difflong1>6.2832)
  30. {
  31. difflong1=difflong1-6.2832;
  32. }
  33. //makesure asineparam is within the domain of function asin
  34. double asinparam1=sqrt(fabs(1.0-.5*cos(difflat1)-.5*cos(difflong1)));
  35. while (asinparam1>1)
  36. {
  37. asinparam1=asinparam1-2;
  38. }
  39. //declare and assign distance output variable
  40. double d1=asin(asinparam1)*2.0*3963.1;
  41. //display desired output
  42. printf("\nDistance traveled =%6.1lf miles", d1);
  43. double pathd=d1;
  44.  
  45. do{
  46. //aquire input values from user
  47. printf("\nEnter position of way point 3 (latitude and longitude): ");
  48. lat3=EOF;
  49. long3=EOF;
  50. scanf("%lf %lf", &lat3, &long3);
  51. //how to break the loop
  52. if (lat3=EOF)
  53. {
  54. break;
  55. }
  56.  
  57. if (long3=EOF)
  58. {
  59. break;
  60. }
  61. //convert degrees to radians
  62. double lat3=lat3*.017453;
  63. double long3=long3*.017453;
  64. //make suure difflat and difflong are within domain of function cos
  65. double difflat2=fabs(lat2-lat3);
  66. double difflong2=fabs(long2-long3);
  67. while (difflat2>6.2832)
  68. {
  69. difflat2=difflat2-6.2832;
  70. }
  71. while (difflong2>6.2832)
  72. {
  73. difflong2=difflong2-6.2832;
  74. };
  75. //makesure asineparam is within the domain of function asin
  76. double asinparam2=sqrt(fabs(1.0-.5*cos(difflat2)-.5*cos(difflong2)));
  77. while (asinparam2>1)
  78. {
  79. asinparam2=asinparam2-2;
  80. }
  81. //declare and assign distance output variable
  82. double d2=asin(asinparam2)*2.0*3963.1;
  83. pathd=pathd+d2;
  84. //display desired output
  85. printf("\nDistance traveled =%6.1lf miles", pathd);
  86. }
  87. while (1==1);
  88.  
  89.  
  90. //make suure difflat and difflong are within domain of function cos
  91. /* ERROR */ double difflatt=fabs(lat1-lat3);
  92. double difflongt=fabs(long1-long3);
  93. /* ERROR */ while (difflatt>6.2832)
  94. {
  95. /* ERROR */ difflatt=difflatt-6.2832;
  96. }
  97. while (difflongt>6.2832)
  98. {
  99. difflongt=difflongt-6.2832;
  100. }
  101. //makesure asineparam is within the domain of function asin
  102. double asinparamt=sqrt(fabs(1.0-.5*cos(difflatt)-.5*cos(difflongt)));
  103. while (asinparamt>1)
  104. {
  105. asinparamt=asinparamt-2;
  106. }
  107. //declare and assign distance output variable
  108. double dt=asin(asinparamt)*2.0*3963.1;
  109.  
  110.  
  111.  
  112.  
  113. //display desired output
  114. printf("\n\n Total Distance traveled =%6.1lf miles\nStart to finish distance =%6.1lf miles", pathd, dt);
  115.  
  116. return 0;
  117. }



--------------------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)
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: type 'double' unexpected

 
0
  #7
Feb 23rd, 2008
Try putting the declaration of difflatt at the beginning of your program (before execution begins with printf).
Last edited by John A; Feb 23rd, 2008 at 7:39 pm.
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 26
Reputation: chopficaro is an unknown quantity at this point 
Solved Threads: 0
chopficaro chopficaro is offline Offline
Light Poster

Re: type 'double' unexpected

 
0
  #8
Feb 24th, 2008
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:

  1.  
  2. //patrick allard
  3. //program4
  4. //prof ed ryder
  5. #include "stdio.h"
  6. #include "stdlib.h"
  7. #include "math.h"
  8. int main()
  9. {double difflatt;
  10. //declare input variables
  11. double lat1, lat2, lat3, long1, long2, long3;
  12. //aquire input values from user
  13. printf("\nEnter position of way point 1 (latitude and longitude): ");
  14. scanf("%lf %lf", &lat1, &long1);
  15. printf("\nEnter position of way point 2 (latitude and longitude): ");
  16. scanf("%lf %lf", &lat2, &long2);
  17. //convert degrees to radians
  18. lat1=lat1*.017453;
  19. lat2=lat2*.017453;
  20. long1=long1*.017453;
  21. long2=long2*.017453;
  22. //make suure difflat and difflong are within domain of function cos
  23. double difflat1=fabs(lat1-lat2);
  24. double difflong1=fabs(long1-long2);
  25. while (difflat1>6.2832)
  26. {
  27. difflat1=difflat1-6.2832;
  28. }
  29. while (difflong1>6.2832)
  30. {
  31. difflong1=difflong1-6.2832;
  32. }
  33. //makesure asineparam is within the domain of function asin
  34. double asinparam1=sqrt(fabs(1.0-.5*cos(difflat1)-.5*cos(difflong1)));
  35. while (asinparam1>1)
  36. {
  37. asinparam1=asinparam1-2;
  38. }
  39. //declare and assign distance output variable
  40. double d1=asin(asinparam1)*2.0*3963.1;
  41. //display desired output
  42. printf("\nDistance traveled =%6.1lf miles", d1);
  43. double pathd=d1;
  44.  
  45. while (1==1)
  46. {
  47. //aquire input values from user
  48. printf("\nEnter position of way point 3 (latitude and longitude): ");
  49. lat3=EOF;
  50. long3=EOF;
  51. scanf("%lf %lf", &lat3, &long3);
  52. //how to break the loop
  53. if (lat3=EOF)
  54. {
  55. break;
  56. }
  57.  
  58. if (long3=EOF)
  59. {
  60. break;
  61. }
  62. //convert degrees to radians
  63. double lat3=lat3*.017453;
  64. double long3=long3*.017453;
  65. //make suure difflat and difflong are within domain of function cos
  66. double difflat2=fabs(lat2-lat3);
  67. double difflong2=fabs(long2-long3);
  68. while (difflat2>6.2832)
  69. {
  70. difflat2=difflat2-6.2832;
  71. }
  72. while (difflong2>6.2832)
  73. {
  74. difflong2=difflong2-6.2832;
  75. };
  76. //makesure asineparam is within the domain of function asin
  77. double asinparam2=sqrt(fabs(1.0-.5*cos(difflat2)-.5*cos(difflong2)));
  78. while (asinparam2>1)
  79. {
  80. asinparam2=asinparam2-2;
  81. }
  82. //declare and assign distance output variable
  83. double d2=asin(asinparam2)*2.0*3963.1;
  84. pathd=pathd+d2;
  85. //display desired output
  86. printf("\nDistance traveled =%6.1lf miles", pathd);
  87. }
  88.  
  89.  
  90.  
  91. //make suure difflat and difflong are within domain of function cos
  92. /* ERROR */ difflatt=fabs(lat1-lat3);
  93. double difflongt=fabs(long1-long3);
  94. /* ERROR */ while (difflatt>6.2832)
  95. {
  96. /* ERROR */ difflatt=difflatt-6.2832;
  97. }
  98. while (difflongt>6.2832)
  99. {
  100. difflongt=difflongt-6.2832;
  101. }
  102. //makesure asineparam is within the domain of function asin
  103. double asinparamt=sqrt(fabs(1.0-.5*cos(difflatt)-.5*cos(difflongt)));
  104. while (asinparamt>1)
  105. {
  106. asinparamt=asinparamt-2;
  107. }
  108. //declare and assign distance output variable
  109. double dt=asin(asinparamt)*2.0*3963.1;
  110.  
  111.  
  112.  
  113.  
  114. //display desired output
  115. printf("\n\n Total Distance traveled =%6.1lf miles\nStart to finish distance =%6.1lf miles", pathd, dt);
  116.  
  117. for(;;);
  118. return 0;
  119. }








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
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: type 'double' unexpected

 
0
  #9
Feb 24th, 2008
>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.
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."
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: type 'double' unexpected

 
0
  #10
Feb 24th, 2008
Originally Posted by chopficaro View Post
im running msvs6.0
is it my compiler?
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.
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC