By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,998 Members | 2,921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,998 IT Pros & Developers. It's quick & easy.

compiler error

P: 4
Hi, i am new to programming and am having a little problem in running my program on Dev-C++.this is the codes i have used.
i have also got 2 errors: invalid function declaration [build Error] 1


Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<math.h>
  3. int distance
  4.  
  5. {
  6.  
  7.     int float x1 , x2 ,y1, y2 ,d;
  8.     system ("pause")
  9.     printf("\n\t distance formula\t(please enter 0 for all coordinate to quit)");
  10.     while (1==1);
  11.     {
  12.         printf("\nfirst corner:");
  13.         printf("\n x:");
  14.         scanf("%f",&x1);
  15.         printf("Y");
  16.         scanf("%f",&Y1);
  17.  
  18.         printf("\nsecond corner:");
  19.         printf("\n x:");
  20.         scanf("%f,&x2");
  21.         printf("Y:");
  22.         scanf("%f",&Y2);
  23.         if (x1==0,x2==0,Y1==0,Y2==0);
  24.         {
  25.             return 0;
  26.         }
  27.             D=sqrt((x2-x1)*(x2-x1)+(Y2-Y1)*(Y2-Y1));
  28.             prinf("\n distance = %f",d);
  29.                 printf("\n.");
  30.     }
  31. }
  32.  
Can anyone please try to run this program and help me edit the code ASAP.thanks
Aug 9 '07 #1
Share this Question
Share on Google+
8 Replies


Expert 10K+
P: 11,448
Hi, i am new to programming and am having a little problem in running my program on Dev-C++.this is the codes i have used.
i have also got 2 errors: invalid function declaration [build Error] 1


Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<math.h>
  3. int distance
  4.  
  5. {
  6.  
  7.     int float x1 , x2 ,y1, y2 ,d;
  8. ... 
  9.  
Function declarations and definitions need parameter lists, even when they're
empty, so your function definition should look similar to this:

Expand|Select|Wrap|Line Numbers
  1. int distance() // <--- empty parameter list here
  2.  
  3. {
  4. ...
  5.  
kind regards,

Jos
Aug 9 '07 #2

P: 4
Function declarations and definitions need parameter lists, even when they're
empty, so your function definition should look similar to this:

Expand|Select|Wrap|Line Numbers
  1. int distance() // <--- empty parameter list here
  2.  
  3. {
  4. ...
  5.  
kind regards,

Jos


well thanks for your help...I did appreciate your posted solution but am still finding hard to run the program.

[code=cpp]
int distance() // <--- empty parameter list here
........

what do you mean i should empty my parameter list?
could you please specify into detail on how i should go about it. (well detailed).


Thank you.
Aug 9 '07 #3

Expert 10K+
P: 11,448
well thanks for your help...I did appreciate your posted solution but am still finding hard to run the program.

Expand|Select|Wrap|Line Numbers
  1. int distance() // <--- empty parameter list here
  2. ........
  3.  
what do you mean i should empty my parameter list?
could you please specify into detail on how i should go about it. (well detailed).


Thank you.
Everything between the parentheses are the parameters; your function doesn't
take any parameters (as far as I can see), so you should have an empty parameter
list as I wrote in the comment. The // comment wasn't an order, it was just a
clarification of what you saw there: an empty parameter list.

kind regards,

Jos
Aug 10 '07 #4

Expert 100+
P: 181
[quote=kingsleyterrace]Hi, i am new to programming and am having a little problem in running my program on Dev-C++.this is the codes i have used.
i have also got 2 errors: invalid function declaration [build Error] 1


Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<math.h>
  3. int distance
  4.  
  5. {
  6.  
  7. int float x1 , x2 ,y1, y2 ,d;
  8. system ("pause")
  9. ....
  10. }
  11.  
You need to terminate function or sytem calls wirh " ; " as well. This would again result in compiler error
Aug 10 '07 #5

FishVal
Expert 2.5K+
P: 2,653
Hi, i am new to programming and am having a little problem in running my program on Dev-C++.this is the codes i have used.
i have also got 2 errors: invalid function declaration [build Error] 1


Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<math.h>
  3. int distance
  4.  
  5. {
  6.  
  7.                 .....................
  8.     while (1==1);                   // remove ";" here
  9.     {
  10.       ..............
  11.                         // remove ";" here and replace "," with ";"    
  12.                         if (x1==0,x2==0,Y1==0,Y2==0);         {
  13.             return 0;
  14.         }
  15.             ....................    }
  16. }
  17.  
Can anyone please try to run this program and help me edit the code ASAP.thanks
Many syntax errors.

Additionally to the previous post you need to remove ";" from "while" and "if" as they treated as end of instruction, the rest in {} will be treated as separate code.
You need to replace "," with ";" in "if" statement.
Aug 12 '07 #6

P: 4
thank you , but that does not seem to be the problem because i have done exactly what i was asked to do but it does not work and i am still getting the same error . i will really appreciate if some one can run the original program and correct it for me please ASAP.
Aug 15 '07 #7

ilikepython
Expert 100+
P: 844
You need to replace "," with ";" in "if" statement.
Semicolon? I think the O/P needs to put and's "&&". or or's "||".
Expand|Select|Wrap|Line Numbers
  1. if ( x1 == 0 && x2 == 0 && y1 == 0 && y2 == 0)
  2. {}
  3. // or....
  4. if (x1 == 0 || x2 == 0 || y1 == 0 || y2 == 0)
  5. {}
  6.  
Aug 15 '07 #8

ilikepython
Expert 100+
P: 844
thank you , but that does not seem to be the problem because i have done exactly what i was asked to do but it does not work and i am still getting the same error . i will really appreciate if some one can run the original program and correct it for me please ASAP.
You have used some variables as they are capitals but you declared them lowercase. Remember, C++ is case-sensetive. For example, in your if you had:
Expand|Select|Wrap|Line Numbers
  1. if (...... Y1 == 0 && Y2 == 0){}
  2.  
  3. // should be ....
  4.  
  5. if (...... y1 == 0 && y2 == 0){}
  6.  
Aug 15 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.