Problem with getting WA in my C program for this question

,

The problem is from the book test your c skills by yashavant p. kanetkar.
Transform the scale of temperature:
In this problem, you have to transform C(Celcius) to (Fahrenheit) or F(Fahrenheit) to C(Celcius). So, you have to give your input temperature either in Celcius or in Fahrenheit.
So, your program should have 2 selection and you have to select the type of input.
Input:

  1. First, you have to choose the input type, I mean, select the temperature scale for input. You should do that by using 1 or 2. 1 for Fahrenheit and 2 for Celcius.
  2. Then input the temperature (it can be both integer and partial)
  3. Do (1 & 2 again and again)

Output:

  1. Your output should be the transformed temperature (by scale).

Example Input:
1
36
2
36
1
98.4

Example Output:
2.22
96.8
36.89

And here is my solution:


And it is the result for this solution in my computer IDE ‘Dev C++’:

1
36
exited, segmentation fault

After giving 2 input it should print a output. But it gives me this. what is segmentation fault? Is my code okay? Or, Is my IDE get dump.
Please clarify me and if there is any wrong with my program then tell me and give me a proper solution.

write the return statement outside the while loop, to prevent termination after the first iteration.
It’d be better if you use a do-while loop and add a termination step instead of the infinite while loop.

1 Like