943,793 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 706
  • C RSS
Sep 3rd, 2009
-2

please debug the error

Expand Post »
  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
Similar Threads
Reputation Points: -1
Solved Threads: 0
Newbie Poster
furqankhyraj is offline Offline
14 posts
since Aug 2009
Sep 3rd, 2009
0

Re: please debug the error

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.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Sep 3rd, 2009
0

Re: please debug the error

you are expecting function max to return maximum value but its return type is void.
Reputation Points: 46
Solved Threads: 6
Light Poster
codeguru_2009 is offline Offline
31 posts
since Aug 2009
Sep 3rd, 2009
-2

Re: please debug the error

#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);
}
Reputation Points: -1
Solved Threads: 0
Newbie Poster
furqankhyraj is offline Offline
14 posts
since Aug 2009
Sep 3rd, 2009
0

Re: please debug the error

the function, max, needs to be an int.

do not put 'int' in the arguments when you call the function.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Sep 4th, 2009
1

Re: please debug the error

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]
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 4th, 2009
1

Re: please debug the error

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.
Reputation Points: 651
Solved Threads: 35
Posting Whiz in Training
yellowSnow is offline Offline
201 posts
since Jul 2009
Sep 5th, 2009
0

Re: please debug the error


#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.
Reputation Points: 13
Solved Threads: 3
Junior Poster
Gaiety is offline Offline
111 posts
since Sep 2009
Sep 5th, 2009
0

Re: please debug the error

Click to Expand / Collapse  Quote originally posted by Gaiety ...
you just need to make the above changes.
Does that include the use of void main() as well? I sincerely hope not.
Reputation Points: 651
Solved Threads: 35
Posting Whiz in Training
yellowSnow is offline Offline
201 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Problem working with POSIX threads
Next Thread in C Forum Timeline: Helppppppppppppppp!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC