Hello,
I am fairly new to c and i am finding it hard to spot why a part of a program I am making is not working. The program lets you work out the area and circumference of a circle. This is the code:

#include <stdio.h>
#include <math.h>

int area() ;
int circ() ;



int main()
{


char choice ;


printf("\n Do you want circumference(c) or area(a): ") ;
scanf("%c" , &choice ) ;
if(choice = 'c') { int circ() ; }
if(choice = 'a') { int area() ; }
else { int main() ; }

return 0 ;
}


int area()
{
float radius , pi = 3.141592 ;

printf( "What is the radius: ") ;
scanf( "%f" , &radius ) ;
printf( "\n The Area is %f \n" , pi*(radius*radius) ) ;
return 0 ;
}

The issue is that after i type a letter in for the first input, it stops runninig the program. The compiler that I am using (cygwin) did not give me any errors.I have not finished yet.

Thank you

line 18 and 19 are wrong. int circle() is a function prototype, not a function call.

if(choice = 'c') { circ() ; }

line 20: never, ever call main(). Even though it's a function it is reserved for call by the operating system when the program starts. Instead, you should put lines 16-19 in a loop.

Also line 20 else { int main() ; }
This is another function prototype, though even if you wrote:

else
{
    main();  // recursive call to main
}

Recursively calling main() should not be done.

In function: int area() you may as well change it to void area() as you are not returning any result of the function.
So either change to return; or you can omit the return

Also,when u declare char,u may declare like this char choice[2],then in the if else,u may do like this, if (choice[0]=='c') s0 the program will go check to that char

Also,when u declare char,u may declare like this char choice[2],then in the if else,u may do like this, if (choice[0]=='c') s0 the program will go check to that char

And then you would simply not use the second slot of the array? I can't think of any reason why you would want to do that. The only possible use of an array here would be an array consisting of valid commands matched to appropropriate functions by using function pointers. (Either by combining them in a struct or by using two arrays with linked indexes)

Also, semi-necro.

Just change frm 2 to 1,.nothing will happen either u want to put what number,bcoz in if else we state back the slot of aray that need to be check

Just change frm 2 to 1,.nothing will happen either u want to put what number,bcoz in if else we state back the slot of aray that need to be check

I still don't get what you mean. There seems to be a bit of a language barrier as well. (no offense) I don't get what you're trying to say here. Maybe provide a short code example instead?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.