Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Dev Shed Forums Sponsor:
#1
July 10th, 2003, 11:24 PM
 jinkhai
Junior Member

Join Date: Jul 2003
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
function problem

i have some problem with the function of my codes..anybody can help me to solve this??
------------------------------------
Code:
```#include <stdio.h>
#include <conio.h>
int area1(int,int,int);
double area2(double,double,double);
main()
{
int choice,a,b,square;
double x,y,triangle;
clrscr();
do
{
printf("Calculate an area of : \n1. Square\n2. Triangle\n3. Circle\n");
printf("Please give your choice [1/2/3] : ");
scanf("%d",&choice);
if(choice>=4)
{
printf("Should provide 1-3 options value.\n");
}
}while(choice>=4);
if(choice==1)
{
area1(a,b,square);
}
else                                          
if(choice==2)
{
area2(x,y,triangle);
}
getche();
}

int area1(int a,int b,int square)
{
printf("Enter height and base : ");
scanf("%d%d",&a,&b);
square=a*b;      
printf("The area of triagle is %d",square);
return(area);
}

double area2(double x,double y,double triangle)
{
printf("Enter height and base : ");
scanf("%d%d",&x,&y);
triangle=0.5*x*y;
printf("The area of triagle is %d",triangle);
return(area);
}```

--------------------------------
[edited by Onslaught to add code tags for easier viewing the code]

Last edited by Onslaught : July 11th, 2003 at 09:07 AM.

#2
July 10th, 2003, 11:49 PM
 infamous41md
not a fan of fascism (n00b)

Join Date: Feb 2003
Location: ct
Posts: 2,756
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 94
you have to tell us the problem to be helped. what is the compiler error, what line did it occur on? one thing i noticed is you say:
Code:
`return(area);`
yet i see no variable named area in those functions. Did you mean to say return(square) or return(triangle) as those variables seem to hold what your looking for.

#3
July 11th, 2003, 06:03 AM
 jinkhai
Junior Member

Join Date: Jul 2003
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
the problem there written
possible using definition 'a' before defintion'
like that

and also for b, x,y,square and triangle and area.

u can copy my code and then run it

#4
July 11th, 2003, 06:05 AM
 St!ng
Junior Member

Join Date: Jul 2003
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
i dont know if my solution works, cause i dont have a compiler, but i hope this will help you :-)

your return types of your functions don't fit together.....

first of all:
you declered your function like this:
Quote:
 int choice,a,b,square; double x,y,triangle;

but you executed them like that:
Quote:
 area1(a,b,square); area2(x,y,triangle);

it should be like this:
Quote:
 int area = area1(a,b,square) ...

but theres another problem

the parameters of your function arent initiated....

the right code would be:
[/quote]
..... //main function
if(choice==1)
{
printf("Square of area1 = %d", area1());
}
.......//main

int area1()
{
printf("Enter height and base : ");
scanf("%d%d",&a,&b);
return a*b;
}
[/quote]

#5
July 11th, 2003, 07:59 AM
 jinkhai
Junior Member

Join Date: Jul 2003
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
ok man..i changed everything to simple,let start with simple 1.
but problem still occur, ' undefined symbol 'a' '.
----------------
#include <stdio.h>
#include <conio.h>
int area1(int,int);
main()
{
int choice;
clrscr();
do
{
printf("Calculate an area of : \n1. Square\n2. Triangle\n3. Circle\n");
printf("Please give your choice [1/2/3] : ");
scanf("%d",&choice);
if(choice>=4)
{
printf("Should provide 1-3 options value.\n");
}
}while(choice>=4);
if(choice==1)
{
printf("The area of triagle is %d",area1(a,b));
}
getche();
}

int area1(int a,int b)
{
printf("Enter height and base : ");
scanf("%d%d",&a,&b);
return a*b;
}
------------------

#6
July 11th, 2003, 08:09 AM
 jinkhai
Junior Member

Join Date: Jul 2003
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
hei man, i changed everything again to this.declare the int inside the local declaration.
make everything become this.
-----------------------------------
#include <stdio.h>
#include <conio.h>
int area1();
main()
{
int choice;
clrscr();
do
{
printf("Calculate an area of : \n1. Square\n2. Triangle\n3. Circle\n");
printf("Please give your choice [1/2/3] : ");
scanf("%d",&choice);
if(choice>=4)
{
printf("Should provide 1-3 options value.\n");
}
}while(choice>=4);
if(choice==1)
{
printf("The area of triagle is %d",area1());
}
else
if(choice==2)
{

}
getche();
}

int area1()
{
int a,b;
printf("Enter height and base : ");
scanf("%d%d",&a,&b);
return a*b;
}
------------------------
hopefully no problem for this codes, everything run smoothly, this make me advancing a step more to proceed the triangle and circle area.

#7
July 11th, 2003, 09:09 AM
 Onslaught
/(bb|[^b]{2})/

Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 5,163
Time spent in forums: 6 Days 1 h 34 m 20 sec
Reputation Power: 792
In the future please use an appropriate subject title. You can refer to the sticky thread at the top of this forum for more information on how to post a question.

#8
July 11th, 2003, 10:40 AM
 DJ911
Registered User

Join Date: Jun 2003
Posts: 21
Time spent in forums: 1 h 30 m 51 sec
Reputation Power: 0
Code:
```#include <stdio.h>
#include <conio.h>

int area1();
double area2();

void main()
{
int choice;

do{
clrscr();
printf("1. Square\n");
printf("2. Triangle\n");
printf("3. Circle\n");
printf("0. Exit\n");
printf("Choice : ");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("\nSquare = %d",area1());
break;
case 2:
printf("\nTriangle %f",area2());
break;
case 0:
exit(1);break;
default:
printf("\nProvide useful choice");
}
getch();
}while(choice!=0);
}

int area1()
{
int a, b;
printf("\nter height and base : ");
scanf("%d%d",&a,&b);
return(a*b);
}

double area2()
{
double x, y;
printf("\nEnter height and base : ");
scanf("%d%d",&x,&y);
return(0.5*(x*y));
}```

Last edited by DJ911 : July 12th, 2003 at 06:24 AM.

#9
July 11th, 2003, 12:29 PM
 jinkhai
Junior Member

Join Date: Jul 2003
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
hm..
for c programming, why not declaration of function make inside braces 1?

should be

area1(int a,int b)

bla bla bla

like that....
according to my univers's books, it should be like that.

#10
July 11th, 2003, 12:52 PM
 DJ911
Registered User

Join Date: Jun 2003
Posts: 21
Time spent in forums: 1 h 30 m 51 sec
Reputation Power: 0
hey Jinkhai
i just write an example code.
it is not universal convension

#11
July 11th, 2003, 03:01 PM
 jinkhai
Junior Member

Join Date: Jul 2003
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
but if i put area1(int a,int b)
{}

the whole things cannot run at all..

#12
July 11th, 2003, 06:28 PM
 3dfxMM
Contributing User

Join Date: Aug 2002
Posts: 272
Time spent in forums: 6 Days 17 h 57 m 24 sec
Reputation Power: 18
I think the point is that neither area1 nor area2 need to have parameters passed in to them. Local variables will work just fine in this case so you can just not bother with the parameters. It's even a tiny bit faster.

#13
July 12th, 2003, 05:07 AM
 jinkhai
Junior Member

Join Date: Jul 2003
Posts: 18
Time spent in forums: < 1 sec
Reputation Power: 0
hm..seems this is a better way..but my skool just teach all the **** things with declaration inside the braces. area1(int a, int b)

thanx a lot man..
gonna finish this project soon..next week monday gonna pass up to tutor.

regards,
khai

 Viewing: Dev Shed Forums > Programming Languages > C Programming > function problem

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |