please debug the error

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2009
Posts: 10
Reputation: furqankhyraj has a little shameless behaviour in the past 
Solved Threads: 0
furqankhyraj furqankhyraj is offline Offline
Newbie Poster

please debug the error

 
-2
  #1
Sep 3rd, 2009
  1. #inclxude<conio.h>
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. max(int a,int b,int c);
  5. void main (void)
  6. {
  7.  
  8. clrscr();
  9. int a,b,c,max;
  10. long z;
  11. printf("input three numbers by giving space");
  12. scanf("%d %d %d",&a,&b,&c);
  13. z=max(a,b,c);
  14. printf("Max value is %lb",z);
  15. getch();
  16. }
  17. void max(int a ,int b,int c )
  18. {
  19. if(a>b&&a>c)
  20. return(a);
  21. if(b>c&&b>a)
  22. return(b);
  23. return(c);
  24. }

i make that program to find the maximum value. please help
Last edited by John A; Sep 5th, 2009 at 1:51 am. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,634
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 122
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: please debug the error

 
0
  #2
Sep 3rd, 2009
void max(...

has no return type (it's void) but you're trying to return integers. and yet, you have the function attempting to assign a value to a long integer. why long? change it to int, and change the return type of max to int.
Last edited by jephthah; Sep 3rd, 2009 at 3:40 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 31
Reputation: codeguru_2009 is on a distinguished road 
Solved Threads: 6
codeguru_2009 codeguru_2009 is offline Offline
Light Poster

Re: please debug the error

 
0
  #3
Sep 3rd, 2009
you are expecting function max to return maximum value but its return type is void.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 10
Reputation: furqankhyraj has a little shameless behaviour in the past 
Solved Threads: 0
furqankhyraj furqankhyraj is offline Offline
Newbie Poster

Re: please debug the error

 
-2
  #4
Sep 3rd, 2009
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
max(int a,int b,int c);
void main ()
{

clrscr();
int a,b,c,max;
long z;
printf("input three numbers by giving space");
scanf("%d %d %d",&a,&b,&c);
max=max(int a, b, c);there it is giving expression syntax
printf("Max value is %d",max);
getch();
}
max(int a ,int b,int c )
{
if(a<b&&a<c)
return(a);
if(b<c&&b<a)
return(b);
return(c);
}
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,634
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 122
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: please debug the error

 
0
  #5
Sep 3rd, 2009
the function, max, needs to be an int.

do not put 'int' in the arguments when you call the function.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,667
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 476
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: please debug the error

 
1
  #6
Sep 4th, 2009
furqankhyraj,

Why don't you go get a read,

1. announcement - How to post your problems?
2. Should I used void main() or int main()?
3. Non-Portable Headers Files - conio.h, graphics.h
4. C - Functions

Use code tag to post source code.
for example,

[code=c]
statements....
[/code]
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 201
Reputation: yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold 
Solved Threads: 35
yellowSnow's Avatar
yellowSnow yellowSnow is offline Offline
Posting Whiz in Training

Re: please debug the error

 
1
  #7
Sep 4th, 2009
Besides all the other "evils" in your code that others have pointed out already, the logic of your max() function in your last post is incorrect. It appears to be returning the minimum value out of the three values passed in to the function.

You should consider yourself lucky that you're even getting people responding to your thread - you have made 10 posts and you still haven't figured out how to use code tags - although that is probably the least of your problems going by the poor quality of your code. You obviously need to study the core basics of C in more detail. And if you have, then you need to study harder.
Manic twiddler of bits
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 76
Reputation: Gaiety is an unknown quantity at this point 
Solved Threads: 2
Gaiety's Avatar
Gaiety Gaiety is offline Offline
Junior Poster in Training

Re: please debug the error

 
0
  #8
Sep 5th, 2009
Originally Posted by furqankhyraj View Post

#inclxude<conio.h>
// shoulld be #include<conio.h>

#include<stdio.h>
#include<stdlib.h>
max(int a,int b,int c);
void main (void)
{

clrscr();
int a,b,c,max;
long z;
printf("input three numbers by giving space");
// avoid spaces between arguments of scanf
scanf("%d %d %d",&a,&b,&c);
z=max(a,b,c);
printf("Max value is %lb",z);
getch();
}
// when you are returning values from function need to specify the //return type
// here the return type should be int as you are returning integer //value.

// int max(int a ,int b,int c )
 
void max(int a ,int b,int c )
{
 if(a>b&&a>c)
 return(a);
if(b>c&&b>a)
return(b);
return(c);
}

i make that program to find the maximum value. please help
you just need to make the above changes.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 201
Reputation: yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold yellowSnow is a splendid one to behold 
Solved Threads: 35
yellowSnow's Avatar
yellowSnow yellowSnow is offline Offline
Posting Whiz in Training

Re: please debug the error

 
0
  #9
Sep 5th, 2009
Originally Posted by Gaiety View Post
you just need to make the above changes.
Does that include the use of void main() as well? I sincerely hope not.
Manic twiddler of bits
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC