Why won't this if else statement work?

I can't understand why the if else statement does not work to let the user choose no and end the program. It will always respond by running main again. Anyone see what I'm doing wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

#include <stdio.h>

long cube(long x);

long input, answer;

int again;

main()
{
	printf("Enter an integer value:  ");
	scanf("%ld", &input);
	answer = cube(input);
	printf("\nThe cube of %ld is %ld.", input, answer);

	printf("\nAnother? <yes(1) or no(2)>...\n");
	scanf("%d", &again);
	
	if(again=1)
	main();

	else	
	return 0;
}

long cube(long x)
{
	long x_cubed;
	x_cubed = x*x*x;
	return x_cubed;
}
try

if(again==1)
main();

else
return 0;
worked for me
Thanks ogranatw! Woops! Syntax oversight!

Tzuch
Topic archived. No new replies allowed.