Here, I tried to use the function to return the values of a pointer variable *V as this pointer takes the address of variable "volume". Now In order to continue to the while loop repeatedly, I am asking the user to enter 'y' if they want to continue doing the calculation again. But the program somehow terminates after displaying the last printf statement. Could you help me figure out where I might have gone wrong?
#include<stdio.h>
#include<stdlib.h>
double Vol(int h, int l, int w, double *V ){
*V = h*l*w;
return *V;
}
int main(){
int height, length, width;
double volume;
char Answer;
while(1){
printf("\nEnter the values :");
printf("\nheight : ");
scanf("%d", &height);
printf("length : ");
scanf("%d",&length);
printf("width : ");
scanf("%d",&width);
fflush(stdin);
printf("The volume is : %f\n",Vol(height, length, width, &volume));
printf("do you want to do it again ? ");
scanf("%c",&Answer);
if(Answer == 'y')
continue;
else
exit(0);
}
}